Sql - Insert problem in MsAccess

Hello!!!
J have problem with INSERT function, I use MsAccessm as database. My query is :
INSERT INTO [Produkty-www] ( Id,Nazwa,Kod,Cena)
VALUES 6646545,"Zlaczka
prosta 22mm 1/2 ' z (KRoCIEC)",'JGK22-1/2Z',10.00)
this is very import symbol ' in 1/2 ' z must be at the place. When I execute this query I have exception. In maaccess I create query and also msaccesse show me when is the bad part of query the sybmol ' is underline.
So I create a new query but in access :
INSERT INTO [Produkty-www] ( Id,Nazwa,Kod,Cena) VALUES (6646545,"Zlaczka prosta 22mm 1/2 ' z (KRoCIEC)",'JGK22-1/2Z',10.00)
and ok access add record, now I copy this query to my java application and I also have exception.
Why this query don`t work.. ?

Ok, it`s done :     
PreparedStatement statement = podlaczenie.prepareStatement("INSERT INTO [Produkty-www] (id, Nazwa, Kod, Cena) VALUES (?,?,?,?)");
statement.setInt(1,2);
statement.setString(2,"ffsdfds'fdsfs");
statement.setString(3,"kod");
statement.setInt(4,124);
statement.execute();
But I need a sql query print to console, a search a method of statement but I dont find that I look for, it is some method that give my sql query in string ?
Thank`s for help

Similar Messages

  • Export "SQL Insert" problem

    Hello to everybody,
    I'm using SQL Developer 1.0.0.15.57 in an Italian Windows XP Professional SP2.
    I'm exporting a table as "SQL Insert" and I have the following problem: the exported INSERT instruction contains, i.e., 123,45 instead of 123.45 so, running the INSERT, Oracle 10 tells me too much values were given because
    Value1, 123,45, Value2, ...
    is wrong: it should be
    Value1, 123.45, Value2, ...
    I think this is a problem of the Internation settings (in Italy we use , as decimal separator instead of the . ). Does anybody know how to solve this?
    For the moment I have changed my Internal Settings with USA and, after arestart, this is fixed. However now there is another less heavy problem: the dates are written in English like to_date('01-JAN-06', ... instead of to_date('01-GEN-06', ... but I can fix it with a search&replace function.
    Thank you in advance
    Andrea

    Hello. I'm trying to find a solution for this too. In Venezuela we also use , as decimal separator. Has anybody found a solution for this? It is absolutly necesary to change the international settings of my pc?
    Thanks!
    Message was edited by:
    JeanK

  • SQL INSERT problem - help please

    Hello,
    I'm having a problem with INSERT statement.
    There is a "ShowFinal.jsp" page, which is a list of candidates who selected from the second
    interview. The user picked some candidates from the list and conduct the 3rd interview. After
    he check suitable candidates(who are selected from the 3rd interview) from the list , enter
    basic salary for every selected candidate, enter date of interview and finally submit the form.
    These data should be save into these tables.
    FinalSelect(nicNo,date)
    EmpSalary(nicNo,basicSal)
    In this "ShowFinal.jsp" page, it validates the following conditions using JavaScript.
    1) If the user submit the form without checking at least one checkbox, then the system should be
    display an alert message ("Please select at least one candidate").
    2) If the user submit the form without entering the basic salary of that candidate which was
    checked, then the system should be display an alert message ("Please enter basic salary").
    These are working well. But my problem is how to wrote the "AddNewFinal.jsp" page to save these
    data into the db.
    Here is my code which I have wrote. But it points an error.
    "AddNewFinal.jsp"
    String interviewDate = request.getParameter("date");
    String[] value = request.getParameterValues("ChkNicno");
    String[] bs = request.getParameterValues("basicSal");
    String sql ="INSERT INTO finalselect (nicNo,date) VALUES(?,?)";
    String sql2 ="INSERT INTO EmpSalary (nicNo,basicSal) VALUES(?,?)";
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2 = connection.prepareStatement(sql2);
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1 = connection.prepareStatement(sql);
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    Here is the code for "ShowFinal.jsp".
    <form name="ShowFinal" method="POST" action="AddNewFinal.jsp" onsubmit="return checkEmpty() &&
    ValidateDate();">
    <%--  Loop through the list and print each item --%>
    <%
         int iCounter = 0; //counter for incremental value
         while (igroups.hasNext()) {
              Selection s = (Selection) igroups.next();
              iCounter+=1; //increment
    %>
    <tr>
         <td style="background-color:ivory" noWrap width="20">
         <input type="checkbox" name="<%= "ChkNicno" + iCounter %>"      
    value="<%=s.getNicno()%>"></td>
            <td style="background-color:ivory" noWrap width="39">
                 <%= s.getNicno() %>  </td>
         <td style="background-color:ivory" noWrap width="174">
              <input type="text" name="<%= "basicSal" + iCounter %>" size="10"> </td>
    </tr>
    <%
    %>
    Date of interview<input type="text" name="date" size="17"></td>
    <input type="submit" value="APPROVE CANDIDATE" name="B1" style="border: 1px solid #0000FF">
    </form>........................................................
    Here is the error generated by TOMCAT.
    root cause
    java.lang.NullPointerException
         at org.apache.jsp.AddNewFinal_jsp._jspService(AddNewFinal_jsp.java:70)
         at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
    I have goto the file "AddNewFinal_jsp.java". The line 70 points to the following line.
    for(int i=0; i < value.length; i++){ [/b]
    Please can someone help me to solve this problem? Please help me to do this task.
    Thanks.

    Hi Casabianca ,
    It is clearly that your problem is not on the database end, more like a servlet/jsp issue.
    I will not comment on the javascript portion, but rather the 2 jsps.
    a simple way to trace what's go wrong is to check the final result (the html code) of the first jsp (showFinal.jsp), and compare against what is expected by the 2nd jsp (AddNewFinal.jsp). Most browser do provide "view source" on the page visited.
    the following code
    <input type="checkbox" name="<%= "ChkNicno" + iCounter %>" value="<%=s.getNicno() %>">
    <input type="text" name="<%= "basicSal" + iCounter %>"
    would likely to be "translated" to html code something as follow:
    <input type="checkbox" name=""ChkNicno0" value="nicNo>">
    <input type="text" name="basicSal0">
    the original code in "AddNewFinal.jsp" using
    request.getParameterValues("ChkNicno");
    which looking for a none exist http request parameter (sent as "ChkNicno0",etc but look for "ChkNicno"), which has explained before.
    the second attempt to use String[] value = request.getParameterValues("ChkNicno" + iCounter); give Cannot resolove symbol :iCounter. because iCounter never defined in the 2nd jsp!
    Most of the error message do give clue to cause of error... : )
    not too sure on your intension, assume you wish to update only those selected (checked) row to db.
    some suggestions:
    1) <input type="text" name="ChkNicno" size="10"> </td>...
    <input type="text" name="basicSal" size="10"> instead.
    then use javascript to based on checked element index (refer to javascript spec for more details), for those index not checked, clear off the correspond index "basicSal" field value.
    e.g. ChkNicno[1] is not checked, empty basicSal[1] value before submission.
    This will give us only selected rows values.
    2) retain the code
    String[] value = request.getParameterValues("ChkNicno");
    String[] bs = request.getParameterValues("basicSal");at 2nd jsp, as now the http request will pass parameters using "ChkNicno" and "basicSal".
    3) some change to the code for optimization
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2 = connection.prepareStatement(sql2);
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1 = connection.prepareStatement(sql);
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    to
    pstmt1 = connection.prepareStatement(sql);
    pstmt2 = connection.prepareStatement(sql2);
    for(int i=0; i < value.length; i++){
         String temp = value;     
         for(int x=0; x < bs.length; x++){
              String basic = bs[x];
              pstmt2.setString(1, temp);
              pstmt2.setString(2, basic);
              int RowCount1= pstmt2.executeUpdate();
         pstmt1.setString(1, temp);
         pstmt1.setString(2, interviewDate);
         int RowCount= pstmt1.executeUpdate();
    preparestatement created once should be sufficient as we do not change the sql statement throughout the loop.
    there are better solutions out there, this just some ideas and suggestions.Do try out if you wish.
    Hope it helps. : )

  • SQL insert statement in java with Excel file

    Dear all,
    I wrote a program is as the follow:
    import java.io.*;
    import java.sql.*;
    public class handleExcel
         Connection con = null;
         Statement stmnt = null;
         public handleExcel()
              String excel = "C:\\EGS\\app_files\\info_update_form_exported_data.xls";
              try
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   String str="jdbc:odbc:DRIVER=Microsoft Excel Driver (*.xls);DBQ=" + excel + ";";
         String sql = "insert into [Sheet1$] (Name, Age, Test1, Test2, Test3) values ('mary','16','aa','bb','vv')";
                   con = DriverManager.getConnection(str, "", "");
                   stmnt = con.createStatement();
                   stmnt.executeUpdate(sql);
              catch(Exception e)
                   System.out.println("con is error!!");
                   e.printStackTrace();
         public static void main(String[] args)
              handleExcel TestHpc = new handleExcel();
    But when I run it, the error is as the follow:
    java.sql.SQLException: [Microsoft][ODBC Excel Driver]
         at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
         at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
         at sun.jdbc.odbc.JdbcOdbc.SQLExecDirect(JdbcOdbc.java:3111)
         at sun.jdbc.odbc.JdbcOdbcStatement.execute(JdbcOdbcStatement.java:338)
         at sun.jdbc.odbc.JdbcOdbcStatement.executeUpdate(JdbcOdbcStatement.java:288)
         at hk.gov.edb.util.handleExcel.<init>(handleExcel.java:31)
         at hk.gov.edb.util.handleExcel.main(handleExcel.java:97)
    Please help me to solve this problem. Thank you so much for your help!
    Regards,
    kzyo

    Hi
    You can use the[b] jakarta POI api in order to read/write Excel file from java. Pure Java, no drivers nedeed.
    I tested and ok.
    Hope this helps

  • An insert problem

    hi
    i am inserting in a table values like-----
    insert into tab1(col1) values(seq.nextval);
    my col1 of tab1 is of varchar2(20) datatype and seq is a sequence.
    now an error is coming
    PL/SQL: ORA-00984: column not allowed here
    why??

    does not look like any error here...
    14:14:07 SQL> CREATE TABLE tab1 (col1 VARCHAR2(20));
    Table created.
    Elapsed: 00:00:00.00
    14:14:20 SQL> CREATE SEQUENCE seq START WITH 1 INCREMENT BY 1;
    Sequence created.
    Elapsed: 00:00:00.00
    14:14:46 SQL> INSERT INTO tab1(col1) VALUES(seq.NEXTVAL);
    1 row created.
    Elapsed: 00:00:00.00
    14:15:06 SQL> SELECT * FROM tab1;
    COL1
    1
    Elapsed: 00:00:00.00
    14:15:13 SQL> INSERT INTO tab1(col1) VALUES(seq.NEXTVAL);
    1 row created.
    Elapsed: 00:00:00.00
    14:15:22 SQL> SELECT * FROM tab1;
    COL1
    1
    2
    Elapsed: 00:00:00.00can you give more details about your problem, desc of your table, name of the sequence etc...

  • How I can make SQL Insert file on schedule

    Dear Community Members;
    Hope all you will be perfect. I required your urgent response on my query. I want to make an SQL Insert file, means I want to insert data from query in one table and after that, the data export in an SQL file as a SQL Insert file.
    All these things want to do on schedule not manually.
    Can anyone help and guide me how I can do it?

    Dear Members;
    Actually, we are working on two different applications, like sale and account. Now we want to post sale information in account system without any DBLink, for that I want to make a file where my data store in SQL Insert Statement format on scheduling, means I want to create a procedure which create this file on scheduling. After that same as I want to create a procedure in other system for read that file and execute. Now I have been found Oracle functionality but still I am facing a problem. The problem is that my procedure create a file with a single record not the all fetched record. My Procedure is as:
    DECLARE
      fileHandler UTL_FILE.FILE_TYPE;
      INSERT1 VARCHAR2(200);
      INSERT2 VARCHAR2(200);
      cursor c1 is
        select T.QTY, T.SLIP_NO, T.STORE_NO, T.Item_Code
        from test t
        where T.STORE_NO = 1;
    BEGIN
        for cur_rec in c1 loop
        INSERT1 := 'INSERT INTO TEST_2(Item_Code,STORE_NO,QTY,SLIP_NO) VALUES(';
        INSERT2 := INSERT1||CUR_REC.Item_Code||','||CUR_REC.STORE_NO||','||CUR_REC.QTY||','||CUR_REC.SLIP_NO||')' ;
      fileHandler := UTL_FILE.FOPEN('E:\Oracle\admin\udump', 'test_file2.SQL', 'W');
      --UTL_FILE.PUTF(fileHandler, 'Writing TO a file\n');
      UTL_FILE.PUTF(fileHandler, INSERT2);
      UTL_FILE.PUTF(fileHandler, '\n commit;');
      UTL_FILE.FCLOSE(fileHandler);
      END LOOP;
    EXCEPTION
      WHEN utl_file.invalid_path THEN
         raise_application_error(-20000, 'ERROR: Invalid PATH FOR file.');
    END;
    Please suggest/guide me where I am doing something wrong or missing. I'll thankful for your help.

  • Oracle insert problem(records not in the order they are inserted)

    hi, all:
    I tried to insert a word list into a oracle table, everything is fine except that the words are not in the order they are inserted. For example, the words are inserted in the following sequence:
    accreted     
    accreting     
    accretion     
    accretionary     
    accretive     
    bladebone
    bladed     
    bladeless
    bladelike
    When I retrived the resultset from the table and iterate through each of the record, the words are not in the order inserted, i.e., it may look like this,
    accreted     
    accreting     
    bladebone
    bladed     
    accretion     
    accretionary     
    accretive     
    bladeless
    bladelike
    This strange phenomenon won't happen when the word list is small, like 500 words or so, but when the number of words reaches around 10,000, it takes place. My coworker also experienced this problem when trying to insert large volume of data into oracle table.
    The code I used to insert into the DB table:
    BufferedReader reader=new BufferedReader(new FileReader("C:\\Dictionary.txt"));
    while( (line=reader.readLine())!=null )
         sql="INSERT INTO DICT " +
         "VALUES ('" + line +"')";                         
         statement.executeUpdate(sql);
    Any advice will be highly appreciated,
    thanks

    Well, the best thing to do is follows scsi-boy's advice and add the additional column and either put a sequence number in it from the Java side as you insert, or use an Oracle sequence object to put a sequence number in it from the Oracle side (which is sort of like an auto-generated value, but different).
    Note that an Oracle sequence generates numbers in sequence, but possibly with gaps (usually if the database is rebooted), unless you do some things that slow sequences down substantially. Sequences can also be something of a bottleneck on RAC clusters. See:
    http://www.dizwell.com/oracle/articles/autonumbering.html
    However, if your coworker is commiting after each and every insert (which is bad form and slows the database down, -10 points), and if your coworker is also never ever ever updating the columns after they've been inserted, and if your coworker is using Oracle 10g and not some older version such as 9i, then your coworker could use the ORA_ROWSCN pseudo-column to order by. Those are very very severe constraints and you shouldn't begin to consider doing it that way without a very good reason, and right now you and your coworker wouldn't know a good reason if it snuck up and bit you on the butt, you've got a lot of learning the basics first.

  • SQL insert with select statement having strange results

    So I have the below sql (edited a bit). Now here's the problem.
    I can run the select statement just fine, i get 48 rows back. When I run with the insert statement, a total of 9062 rows are inserted. What gives?
    <SQL>
    INSERT INTO mars_aes_data
    (rpt_id, shpdt, blno, stt, shpr_nad, branch_tableS, csgn_nad,
    csgnnm1, foreign_code, pnt_des, des, eccn_no, entity_no,
    odtc_cert_ind, dep_date, equipment_no, haz_flag, schd_no,
    schd_desc, rec_value, iso_ulti_dest, odtc_exempt, itn,
    liscence_no, liscence_flag, liscence_code, mblno, mot,
    cntry_load, pnt_load, origin_state, airline_prefix, qty1, qty2,
    ref_val, related, routed_flag, scac, odtc_indicator, seal_no,
    line_no, port_export, port_unlading, shipnum, shprnm1, veh_title,
    total_value, odtc_cat_code, unit1, unit2)
    SELECT 49, schemaP.tableS.shpdt, schemaP.tableS.blno,
    schemaP.tableS.stt, schemaP.tableS.shpr_nad,
    schemaP.tableM.branch_tableS, schemaP.tableS.csgn_nad,
    schemaP.tableS.csgnnm1, schemaP.tableD.foreign_code,
    schemaP.tableS.pnt_des, schemaP.tableS.des,
    schemaP.tableD.eccn_no, schemaP.tableN.entity_no,
    schemaP.tableD.odtc_cert_ind, schemaP.tableM.dep_date,
    schemaP.tableM.equipment_no, schemaP.tableM.haz_flag,
    schemaP.tableD.schd_no, schemaP.tableD.schd_desc,
    schemaP.tableD.rec_value,
    schemaP.tableM.iso_ulti_dest,
    schemaP.tableD.odtc_exempt, schemaP.tableM.itn,
    schemaP.tableD.liscence_no,
    schemaP.tableM.liscence_flag,
    schemaP.tableD.liscence_code, schemaP.tableS.mblno,
    schemaP.tableM.mot, schemaP.tableS.cntry_load,
    schemaP.tableS.pnt_load, schemaP.tableM.origin_state,
    schemaP.tableM.airline_prefix, schemaP.tableD.qty1,
    schemaP.tableD.qty2,
    schemaC.func_getRefs@link (schemaP.tableS.ptt, 'ZYX'),
    schemaP.tableM.related, schemaP.tableM.routed_flag,
    schemaP.tableM.scac, schemaP.tableD.odtc_indicator,
    schemaP.tableM.seal_no, schemaP.tableD.line_no,
    schemaP.tableM.port_export,
    schemaP.tableM.port_unlading, schemaP.tableS.shipnum,
    schemaP.tableS.shprnm1, schemaP.tableV.veh_title,
    schemaP.tableM.total_value,
    schemaP.tableD.odtc_cat_code, schemaP.tableD.unit1,
    schemaP.tableD.unit2
    FROM schemaP.tableD@link,
    schemaP.tableM@link,
    schemaP.tableN@link,
    schemaP.tableS@link,
    schemaP.tableV@link
    WHERE tableM.answer IN ('123', '456')
    AND SUBSTR (tableS.area, 1, 1) IN ('A', 'S')
    AND entity_no IN
    ('A',
    'B',
    'C',
    'D',
    'E',
    AND TO_DATE (SUBSTR (tableM.time_stamp, 1, 8), 'YYYYMMDD')
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'
    AND tableN.shipment= tableD.shipment(+)
    AND tableN.shipment= tableS.shipnum
    AND tableN.shipment= tableM.shipment(+)
    AND tableN.shipment= tableV.shipment(+)
    <SQL>
    Edited by: user11263048 on Jun 12, 2009 7:23 AM
    Edited by: user11263048 on Jun 12, 2009 7:27 AM

    Can you change this:
    BETWEEN '01-Mar-2009'
    AND '31-Mar-2009'To this:
    BETWEEN TO_DATE('01-Mar-2009', 'DD-MON-YYYY')
    AND TO_DATE('31-Mar-2009','DD-MON-YYYY')That may make no difference but you should never rely on implicit conversions like that, they're always likely to cause you nasty surprises.
    If you're still getting the discrepancy, instead of and INSERT-SELECT, can you try a CREATE TABLE AS SELECT... just to see if you get the same result.

  • Insert Problem jdbc odbc

    I have problem with my Insertion code. here is my code:-
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    import java.lang.Class;
    import java.util.*;
    public class BookForm extends JFrame implements ActionListener
         //attributes
         private JTextField name, address, ICno;
         private JButton cancel, book;
         private JLabel lb1,lb2, lb3, lb4;
         private Container c;
         private Connection con;
         private ResultSet rs;
         private Statement stmt;
         private String looks;
         private String Busno, $seatno, $date, pric;
         public BookForm(String $Busno, String seatno, String date, String $price)
              super("Seat No. "+seatno);
              c = getContentPane();
              c.setLayout(null);
              c.setSize(260,260);
              Busno = $Busno;
              $seatno = seatno;
              $date = date;
              pric = $price;
              // ********** SET UP GUI **********
              try{
              looks = UIManager.getSystemLookAndFeelClassName();
              UIManager.setLookAndFeel(looks);
              SwingUtilities.updateComponentTreeUI(this);
              }//end of try
              catch(Exception e)
                   System.out.println("Error in UIManager");
              lb1 = new JLabel("Name");
              lb1.setSize(60,20);
              lb1.setLocation(30,30);
              lb2 = new JLabel("Address");
              lb2.setSize(60,20);
              lb2.setLocation(30,60);
              lb3 = new JLabel("IC No.");
              lb3.setSize(60,20);
              lb3.setLocation(30,90);
              lb4 = new JLabel("Seat No. : "+$seatno);
              lb4.setSize(100,20);
              lb4.setLocation(30,120);
              name = new JTextField();
              name.setSize(150,20);
              name.setLocation(100,30);
              address = new JTextField();
              address.setSize(150,20);
              address.setLocation(100,60);
              ICno = new JTextField();
              ICno.setSize(150,20);
              ICno.setLocation(100,90);
              cancel = new JButton("Cancel");
              cancel.setSize(70,30);
              cancel.setLocation(30,190);
              cancel.setMnemonic('L');
              book = new JButton("Print & Book");
              book.setSize(100,30);
              book.setLocation(140,190);
              book.setMnemonic('R');          
              c.add(lb1);
              c.add(lb2);
              c.add(lb3);
              c.add(lb4);
              c.add(name);
              c.add(address);
              c.add(ICno);
              c.add(cancel);
              c.add(book);
              cancel.addActionListener(this);
              book.addActionListener(this);
         }//end o BookForm()
         public void actionPerformed(ActionEvent e)
              Object source = e.getSource();
              if(source == book)
                   String nam = name.getText();
                   String add = address.getText();
                   String ic = ICno.getText();
                   String busn = Busno;
                   String seatn = $seatno;
                   String dat = $date;
                   boolean validation = validationFunction();
    if(validation == false)
    JOptionPane.showMessageDialog(null,"Please Fill the Form Completely");
    else{
         try{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                        con = DriverManager.getConnection("jdbc:odbc:Bus","","");
                        stmt=con.createStatement();
                        stmt.executeUpdate("Insert Into PassengerBooking (Name,Address,ICno,BusNo,SeatNo,Date) VALUES ('"+nam+"' , '"+add+"', '"+ic+"', '"+Busno+"', '"+$seatno+"', '"+$date+"')");
         stmt.close();
                        con.close();
         catch(SQLException exc)
                             exc.printStackTrace();
                        catch(Exception exc)
                             exc.printStackTrace();
              else if(source == cancel)
                   this.setVisible(false);
         public boolean validationFunction()
              boolean check = true;
              String nam = name.getText();
              String add = address.getText();
              String ic = ICno.getText();
              if(name.equals(""))
                   check = false;
              else if(add.equals(""))
                   check = false;
              else if(ic.equals(""))
                   check = false;
              return check;
    I get syntax error in my Insert query. my database column name is: Name, Address, ICno, BusNo, SeatNo, Date
    and I have an auto number (BookNo) for that table as a primary key.
    Since I am a student and new in java, I dont know which code I type wrongly..
    Please Help me, This my Assignment which to be submited next week.
    Message was edited by:
    Triagip

    Note that there is a return value involved. I suggest you try the following first.
    executeUpdate
    public int executeUpdate(String sql)
                      throws SQLException
    Executes the given SQL statement, which may be an INSERT, UPDATE, or
    DELETE statement or an SQL statement that returns nothing, such as an
    SQL DDL statement.
    Parameters:
    sql - an SQL INSERT, UPDATE or DELETE statement or an SQL statement
    that returns nothing
    Returns:
    either the row count for INSERT, UPDATE or DELETE statements, or 0 for
    SQL statements that return nothing
    Throws:
    SQLException - if a database access error occurs or the given SQL
    statement produces a ResultSet object
    try {
      int returnValue = 0;  // Added
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      System.out.println("Step 1 complete");
      con = DriverManager.getConnection("jdbc:odbc:Bus","","");
      System.out.println("Step 2 complete");
      stmt=con.createStatement();
      System.out.println("Step 3 complete");
      returnValue = stmt.executeUpdate("Insert Into PassengerBooking "
                                      +"(Name,Address,ICno,BusNo,SeatNo,Date) "
                                      +"VALUES ('"+nam+"' , '"+add+"', '"+ic+"', '"+Busno+"', '"+$seatno+"', '"+$date+"')");
      System.out.println("Inserted ["+returnValue"+"] rows");
      stmt.close();
      con.close();
    }I absolutely agree with the advise you received in isolating the SQL pblms, by making sure the insert statement works apart from the Java wrapper code.

  • Jdbc sql insert to oracle DB.

    Dear All,
    I'm using the jdbc connector to insert data directly into an Oracle database table.  I've got the SQL insert command which XI has generated by using the logSQLStatement parameter and I've proved the statement is good by pasting it directly into Toad where it is executed perfectly.  However XI is throwing the following errors;-
    Unable to execute statement for table or stored procedure. 'SI_ORDER' (Structure 'STATEMENT') due to java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric was expected
    MP: exception caught with cause com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'SI_ORDER' (structure 'STATEMENT'): java.sql.SQLException: ORA-01858: a non-numeric character was found where a numeric was expected
    Does anyone know what might be the problem or even where I should start to troubleshoot this?
    Any help is much appreciated.
    Pete.

    Your question is how to load data from a text file into arrays?
    Start with a
    StreamReader to read the file one line at a time.  Then break each line into individual values, and add each value to a
    List<T>.  Then call .ToArray() on each list to set the value of each array-bound parameter.
    David
    David http://blogs.msdn.com/b/dbrowne/

  • CRUD insert problems.

    Hello all,
    I was wondering about DB operations in JSF pages, so I took a look over the Single Page CRUD example. What hitted me was there is a need for a two step insertion, first by issuing a select in search for the biggest ID of the primary key, and after that the insertion of the element with that obtained biggest ID + 1. I see at least 2 problems with this approach:
    1. Concurrency issues.What happends if 2 users are issuing at the same time an insert operation over the same table? There is the possiblity of getting the same ID to insert, and the first one could insert, but the second one would fail even if it's request is logically corect (validated & converted). I see three solutions over the insert problem:
    a. lock on the database (if it's possible).
    b. using a synchronized block in the application bean to get the ID and insert.
    c. using DB specific constructs (e.g. MySQL's AUTO_INCREMENT)
    2. Overhead issues. Why doing in two steps an operation that should be just an insert? Previous a. an b. approaches do not solve our overhead problem, because we still have two steps in insertion; we only synchronize them.
    I was wondering which is the best practice for production quality web applications. Personally because I've picked MySQL as DB I've used AUTO_INCREMENT, but the immediate huge and obvious drawback is dumping DataProvider's capability of changing the storage medium at a glance.

    I'm not sure if I entirely understood your questions here.
    - Concurrency problem.
    database bound Data provider underneath uses CachedRowset, which uses SyncProvider to take care of concurrency problem. If the default RIOptimisticProvider is not enough, it possible to register other more sophisticated SyncProvider.
    You can read about it here.
    http://java.sun.com/j2se/1.5.0/docs/api/javax/sql/rowset/CachedRowSet.html
    - Overhead issue
    I believe, it is possible to let the DB auto increment the primary key field, and left it out in the insertion from data provider.
    - Winston
    http://blogs.sun.com/roller/page/winston?catname=Creator

  • Forte names in an SQL Insert

    The user doc (Accessing Databases p.67) suggests I should be able to do the
    following:
    vTableName : TextData = anObject.GetDBTableName();
    SQL INSERT INTO :vTableName VALUES ( :aDataArray );
    But the compiler complains that the colon before vTableName is a syntax
    error. Is there a way to have my table name come from a variable??
    TIA,
    Eric

    I have already told you what variable is throwing the NPE. Why it is doing it we cannot say from the posted code. There is far too little information.
    As I said, however, having a statement as an instance variable is a very bad practice, and is bound to cause problems.
    There is very little overhead to creating a statement, so there is absolutely no reason not create one every time you need one, and also no reason to hang onto one in an instance variable, either.

  • Public Synonyms for Nested Tables - Insertion Problem

    Hi,
    we are facing a problem during implementation. Our DB set up
    is , we will be having two schema named OWNR and COPY.
    In the schema, OWNR we have to create all the tables,
    types,procedures, packages and obj.....This schema will have
    both DDL and DML privileges.
    In the schema, COPY we are not supposed to create any tables,
    objects. We have to create public synonyms for all the tables,
    types, procedures... in OWNR and grant ALL privilege to the
    schema COPY.The schema, COPY will have only DML privileges.
    The problem is we have some nested tables in our application.
    When I try to insert into the synonym which is created for the
    nested table, it is not allowing me to insert..The whole
    implementation is stucked..Please help.The scripts are given
    below.......
    We have a type name SITA_ADDRESS_TY which is used by the nested
    table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
    table,Table, Public Synonym and granting all privilege to these
    types and tables are
    CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
    SITA_ADDRESS VARCHAR2(10),
    REMARKS VARCHAR2(100)) ;
    PROMPT SITA_ADDRESSS_NT...
    CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
    SITA_ADDRESS_TY ;
    Using this nested table we have created the table,
    UMS_SITA_ADDRESS
    CREATE TABLE UMS_SITA_ADDRESS (
    COMPANY_CODE VARCHAR2 (6) NOT NULL,
    AIRLINE_CODE VARCHAR2 (6) NOT NULL,
    DESTINATION VARCHAR2 (6) NOT NULL,
    SITA_ADDRESS SITA_ADDRESSES_NT)
    TABLESPACE EKUMDAT
    PCTFREE 5
    PCTUSED 40
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 64K
    PCTINCREASE 0
    MINEXTENTS 1
    MAXEXTENTS 505
    FREELISTS 1 FREELIST GROUPS 1 )
    NOCACHE
    NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
    PROMPT SYNONYM SITA_ADDRESS_TY...
    CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
    PROMPT SYNONYM SITA_ADDRESSES_NT...
    CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
    PROMPT UMS_SITA_ADDRESS...
    CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
    Granting Privileges
    PROMPT SITA_ADDRESS_TY...
    GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
    PROMPT SITA_ADDRESSS_NT...
    GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
    PROMPT UMS_SITA_ADDRESS...
    GRANT ALL ON UMS_SITA_ADDRESS TO COPY
    When I connect to copy and desc UMS_SITA_ADDRESS, the structure
    is
    SQL> desc ums_sita_address
    Name Null? Type
    COMPANY_CODE NOT NULL VARCHAR2(6)
    AIRLINE_CODE NOT NULL VARCHAR2(6)
    DESTINATION NOT NULL VARCHAR2(6)
    SITA_ADDRESS
    OWNR.SITA_ADDRESSES_NT
    Why is it so??. Even though I have a synonym for
    SITA_ADDRESSES_NT, it is not referencing the synonym but instead
    refer the OWNR.SITA_ADDRESSES_NT
    Because of this when I try to insert into ums_sita_address(in
    schema COPY), it is giving the following error,
    SQL> insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_NT());
    insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_NT())
    ERROR at line 1:
    ORA-00932: inconsistent datatypes
    But when the same connect to OWNR and try to insert with the
    same stmt, it is inserting...
    Our middle tier can connect only to COPY schema alone..Is there
    anything to be done in the DBA side to achieve this??.
    Please help from your valuabe experience...Or can you ask your
    collegues if they have got a soln to this probs..Our
    implementation team is stucked with this...
    Thanks
    Priya

    Hi
    I am not sure but maybe you need to use this command:
    SQL> insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_TY());
    SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
    Regards

  • Public Synonyms for Nested Tables - Insertion Problem  - Please Help!!!!!

    Hi,
    we are facing a problem during implementation. Our DB set up
    is , we will be having two schema named OWNR and COPY.
    In the schema, OWNR we have to create all the tables,
    types,procedures, packages and obj.....This schema will have
    both DDL and DML privileges.
    In the schema, COPY we are not supposed to create any tables,
    objects. We have to create public synonyms for all the tables,
    types, procedures... in OWNR and grant ALL privilege to the
    schema COPY.The schema, COPY will have only DML privileges.
    The problem is we have some nested tables in our application.
    When I try to insert into the synonym which is created for the
    nested table, it is not allowing me to insert..The whole
    implementation is stucked..Please help.The scripts are given
    below.......
    We have a type name SITA_ADDRESS_TY which is used by the nested
    table SITA_ADDRESSES_NT.Script used for creating the Type,Nested
    table,Table, Public Synonym and granting all privilege to these
    types and tables are
    CREATE OR REPLACE TYPE SITA_ADDRESS_TY AS OBJECT (
    SITA_ADDRESS VARCHAR2(10),
    REMARKS VARCHAR2(100)) ;
    PROMPT SITA_ADDRESSS_NT...
    CREATE OR REPLACE TYPE SITA_ADDRESSES_NT AS TABLE OF
    SITA_ADDRESS_TY ;
    Using this nested table we have created the table,
    UMS_SITA_ADDRESS
    CREATE TABLE UMS_SITA_ADDRESS (
    COMPANY_CODE VARCHAR2 (6) NOT NULL,
    AIRLINE_CODE VARCHAR2 (6) NOT NULL,
    DESTINATION VARCHAR2 (6) NOT NULL,
    SITA_ADDRESS SITA_ADDRESSES_NT)
    TABLESPACE EKUMDAT
    PCTFREE 5
    PCTUSED 40
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 64K
    NEXT 64K
    PCTINCREASE 0
    MINEXTENTS 1
    MAXEXTENTS 505
    FREELISTS 1 FREELIST GROUPS 1 )
    NOCACHE
    NESTED TABLE SITA_ADDRESS STORE AS UMSNT_SITA_ADDRESS ;
    PROMPT SYNONYM SITA_ADDRESS_TY...
    CREATE PUBLIC SYNONYM SITA_ADDRESS_TY FOR SITA_ADDRESS_TY
    PROMPT SYNONYM SITA_ADDRESSES_NT...
    CREATE PUBLIC SYNONYM SITA_ADDRESSES_NT FOR SITA_ADDRESSES_NT
    PROMPT UMS_SITA_ADDRESS...
    CREATE PUBLIC SYNONYM UMS_SITA_ADDRESS FOR UMS_SITA_ADDRESS
    Granting Privileges
    PROMPT SITA_ADDRESS_TY...
    GRANT EXECUTE ON SITA_ADDRESS_TY TO COPY
    PROMPT SITA_ADDRESSS_NT...
    GRANT EXECUTE ON SITA_ADDRESSES_NT TO COPY
    PROMPT UMS_SITA_ADDRESS...
    GRANT ALL ON UMS_SITA_ADDRESS TO COPY
    When I connect to copy and desc UMS_SITA_ADDRESS, the structure
    is
    SQL> desc ums_sita_address
    Name Null? Type
    COMPANY_CODE NOT NULL VARCHAR2(6)
    AIRLINE_CODE NOT NULL VARCHAR2(6)
    DESTINATION NOT NULL VARCHAR2(6)
    SITA_ADDRESS
    OWNR.SITA_ADDRESSES_NT
    Why is it so??. Even though I have a synonym for
    SITA_ADDRESSES_NT, it is not referencing the synonym but instead
    refer the OWNR.SITA_ADDRESSES_NT
    Because of this when I try to insert into ums_sita_address(in
    schema COPY), it is giving the following error,
    SQL> insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_NT());
    insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_NT())
    ERROR at line 1:
    ORA-00932: inconsistent datatypes
    But when the same connect to OWNR and try to insert with the
    same stmt, it is inserting...
    Our middle tier can connect only to COPY schema alone..Is there
    anything to be done in the DBA side to achieve this??.
    Please help from your valuabe experience...Or can you ask your
    collegues if they have got a soln to this probs..We are stucked
    with this...
    Thanks
    Priya

    Hi
    I am not sure but maybe you need to use this command:
    SQL> insert into ums_sita_address values
    ('EK','EK','DXB',SITA_ADDRESSES_TY());
    SITA_ADDRESSES_TY() instead SITA_ADDRESSES_NT
    Regards

  • SQL Insert Error Error in allocating a connection. Cause: No PasswordCreden

    Friends,
    While testing my connection in the Sun java Application Server , I get the following error .
    "SQL Insert Error Error in allocating a connection. Cause: No PasswordCredential found "
    Can somebody please guide ?
    regards
    Dhiraj

    If you are using Netbeans, then this link might help:
    http://forum.java.sun.com/thread.jspa?forumID=136&threadID=598423
    Otherwise, have you try this ?
    Verify your sun-ejb-jar.xml does not use default-resource-princinpal element:
    <res-ref-name>jdbc/pdisasdb</res-ref-name>
    <jndi-name>jdbc/pdisasdb</jndi-name>
    <default-resource-principal>
    <name>myname</name>
    <password>geheim</password>
    </default-resource-principal>
    </resource-ref>

Maybe you are looking for

  • EDI Interface

    Hi,         I've got two questions. Requesting answers. 1. By studying the scenario of an interface, how do we come to know whether to      use ALE or EDI interface? 2. What is the process for configuring the EDI outbound interface when it is File-  

  • 500   Internal Server Error Failed to process request

    Hi , We face problems to run Dev and Qual systems on our Sap portal devices. Production is OK The error message (see hereafter) does not occur on welcome page but on any page that communicate by Web Dynpro with ECC SAP system 500   Internal Server Er

  • Save Thumbnail as PSD? - PSE 7.0

    My backup has become corrupted for about a month's worth of family photos. I would like some images to put in my scrapbook, so my question is... Is there some way to save the thumbnails in Organizer to a PSD? I realize the resolution will be bad but

  • Java Reporting webpage

    I am new to creating reports from JDBC and Java. I am creating a web frontend to a database and want to allow users to load reports based on data from the database, which I access using JDBC and MyBatis. Is there a good, hopefully free, Java tool tha

  • Import records

    hi sapgurus what are import records and how to create import records? plz... answer this.