Problem in inserting data into excel sheet using JAVA ODBC
I am buliding a stand alone application using java swing. and excel 2007 sheet as the backend for storing my data. There are 15 columns in the excel sheet. I am able to insert data into it with just 5 columns. But it shows "syntax error" when i try inserting 15 columns. Is there any limit on the the number of columns that can inserted at a time? or is there any other syntax for lengthy records? I am new to java. so kindly help me out. Thanks in advance :) i have posted the part of the coding (BTW the values in the INSERT INTO statement are added in a single line. for posting properly i have to enter them in a new line. otherwise they are continous. no spacing. just separated by commas)
Code:
try
{
String value1=t1.getText();
String value2=(String)c6.getSelectedItem();
String value3=t3.getText();
String value4=t4.getText();
String value5=t5.getText();
String value6 = (String) c4.getSelectedItem();
String value7=t7.getText();
String value8=t8.getText();
String value9 = (String) c1.getSelectedItem();
String value10 = (String) c2.getSelectedItem();
String value11 = (String) c5.getSelectedItem();
String value12 = (String) c3.getSelectedItem();
String value13=t13.getText();
String value14=t14.getText();
String value15=t15.getText();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=testingApp.xls;READONLY=false");
Statement st=con.createStatement();
String q = "insert into testingApp(CRN,CR_NUM,SOW_N,PSM,LBG,TYPE,VALUE,REMARKS,STATUS,APPROVAL,PLATFORM,
MODEL,START_DATE,END_DATE,CUM_VALUE) Values ('12345','"+value2+"','"+value3+"','"+value4+"','"+value5+"','"+value6+"',
'"+value7+"','"+value8+"','"+value9+"','"+value10+"','"+value11+"',
'"+value12+"','"+value13+"','"+value14+"','"+value15+"')";
int ds = st.executeUpdate(q);
System.out.println("Inserted Sucessfully...!!!");
/* t1.setText(null);
c6.addItem(null);
t3.setText(null);
t4.setText(null);
t5.setText(null);
c4.addItem(null);
t7.setText(null);
t8.setText(null);
c1.addItem(null);
c2.addItem(null);
c5.addItem(null);
c3.addItem(null);
t13.setText(null);
t14.setText(null);
t15.setText(null); */
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
Re: Problem in inserting data into excel sheet using JAVA ODBC
Ouch ! Why Excel? Why not a proper database such as JavaDB/Derby?