Solved

How would you write this database method for sending and [ ] [ ] back

Posted on 2011-09-28
10
194 Views
Last Modified: 2012-05-12
public String[][] getTheHistory(String flightNo, String date)
  {
    // Columns = {"Bokningsnummer", "Flightnummer", "Date", "PersonId", "FirstName", "Lastname", "Type", "Help", "SeatNr", "Price"};
    String [][] temp = new String[1][10];
    temp[0][0] = "123";
    temp[0][1] = "LK202";
    temp[0][2] = "2010-01-01";
    temp[0][3] = "1";
    temp[0][4] = "Anders";
    temp[0][5] = "Paulsson";
    temp[0][6] = "M";
    temp[0][7] = "Y";
    temp[0][8] = "35";
    temp[0][9] = "Black";

    return temp;
  }


I cant really spot how to write it.
0
Comment
Question by:Mickeys
  • 10
10 Comments
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
ID: 36719250
insert into table_name (Bokningsnummer, Flightnummer, Date, PersonId, FirstName, Lastname, Type, Help, SeatNr, Price) values
 (
0
 
LVL 47

Expert Comment

by:for_yan
ID: 36719252
Sorry for that - I din'mean to post it
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719265
Mickeys,

One importantpoint is the waty you write inset staetment
depends not on bhowe looks your data but on how the fields
are defined in the database - therefiore the contebnts of your array do n not tell use how to insert it into
the tabel
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 47

Expert Comment

by:for_yan
ID: 36719269
You need to go to the databse and say

desc table_name

then it will print you which tables are varchar, which are numbers
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719279
Even thought you have temp[0][0] = "123";
it does not tell us if youe column
Bokningnummer
is defined as varchar2 or as number
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719292
In the sql statments all strings should be enclosed in single quotes
the numbers should not have enclosing single quotes, thetefor if you Bokningsnummer
is defined at table creation as number, then you need to have in input string , just

...,123, ...

if it is defined as varchar or varchr2  then you have to have it

....,'123',...

and this is very important - otherwise you'll get eerriors
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719381
Please type
desc table_name
and post the printout

(and I hope desc table_name should work on MySQL also)
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719621


Bokningsnummer  number,
 Flightnummer  varchar, 
Date date,
 PersonId number,
 FirstName varchar,
 Lastname varchar,
 Type varchar, 
Help varchar,
 SeatNr varchar,
 Price number

Open in new window


then you'll have it in java:
ststement.executeUpdate("insert into table_name (Bokningsnummer, Flightnummer, Date, PersonId, FirstName, Lastname, Type, Help, SeatNr, Price) values
(" +  temp[0][0] + ",'" + temp[0][1] + "','" +  temp[0][2] + "'," +  temp[0][3] + ",'" +  temp[0][4] + "','" +  temp[0][5] + "','" +  temp[0][6] + "','" +  temp[0][7] +
"','" +  temp[0][8] + "'," +  temp[0][9] + ")");

Open in new window


The date is in the default format so you put it  in the same format as a string with signgle quotes

I can't understand how Price can correspiond to temp[0][9] = "Black" - so check on that


0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719628
But the main thing to rememeber - the syntax depednes not on your java types and values but on how each filed is
declared in the databse when the table was created
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 500 total points
ID: 36719811
If you expect you'll be having a lot of these interactions between java and database back and forth you may think
about using in future Hibernate which is designed to ensure persistence of java objects in relational databases.

Still it definitely makes sense at least to have some experience with doing it in stariohtforward way
through JDBC - without  at least basic knowledge of that, it is not so easy to understand the stuff about Hibernate

0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question