Solved

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

Posted on 2011-09-28
10
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

630 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