Solved

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

Posted on 2011-09-28
10
192 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now