Results 1 to 2 of 2
Like Tree1Likes
  • 1 Post By sabre150

Thread: Problem in inserting data into excel sheet using JAVA ODBC

  1. #1
    Harini is offline Member
    Join Date
    Aug 2012
    Posts
    1
    Rep Power
    0

    Default 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)

    Java 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());
                	            }
                	        }

  2. #2
    sabre150 is offline Member
    Join Date
    Jul 2012
    Location
    Earth
    Posts
    75
    Rep Power
    0

    Default Re: Problem in inserting data into excel sheet using JAVA ODBC

    Ouch ! Why Excel? Why not a proper database such as JavaDB/Derby?
    quad64bit likes this.

Similar Threads

  1. problem in reading data from excel sheet
    By jainmayank33 in forum Advanced Java
    Replies: 2
    Last Post: 11-03-2011, 04:05 AM
  2. How can i store a data from Excel sheet to an array.
    By deshmukh.niraj04 in forum New To Java
    Replies: 0
    Last Post: 05-03-2011, 07:33 AM
  3. Replies: 0
    Last Post: 03-23-2011, 04:46 AM
  4. Replies: 5
    Last Post: 08-21-2009, 12:03 PM
  5. Save data from Excel sheet to servlet
    By chandu.v in forum Java Servlet
    Replies: 2
    Last Post: 04-10-2008, 02:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •