Solved

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

Posted on 2011-09-28
10
196 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

752 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