Insert Statement with JAVA

I'm trying to insert Data into an access table. Moreover, I'm able to retrieve data on the table (to prove that I'm connecting fine)... I just can't insert Data
try
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con = DriverManager.getConnection(url);
               System.out.println("Connection Successful");
               Statement st = con.createStatement();
               ResultSet rs = st.executeQuery("INSERT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
               rs.close();
               processQuery(con, st); // does what is nessesary to complete the current request
               st.close();
               con.close();
          catch (ClassNotFoundException e)
               System.out.println("failed to load OBCD driver. ");
               System.out.println ("Class errros: " + e);
          }For some reason, I don't have any errors Its just not inserting the data to the table.. any help would be greatly appreciated

try
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               Connection con = DriverManager.getConnection(url);
               System.out.println("Connection Successful");
               Statement st = con.createStatement();
               //ResultSet rs = st.executeQuery("SELECT INTO Worker VALUES ('" + strDataName + "', '" + strDataDept + "', '" + dblDataHoursWrked + "', '" + dblDataHourlyWage + "', '" + dblDataPay + "')");
Here use update query "executeUpdate("UPDATE TABLENAME SET COLUMN=VALUE,.........................WHERE CANDITION );
rs.close();
               processQuery(con, st); // does what is nessesary to complete the current request
               st.close();
               con.close();
          catch (ClassNotFoundException e)
               System.out.println("failed to load OBCD driver. ");
               System.out.println ("Class errros: " + e);
U CHECK IT ,I THINK IT WILL WORK

Similar Messages

  • INSERT statement in Java and MS Access

    Hi all,
    can anyone please tell me how to insert data to an MS Access table using JSP i tried INSERT statement of java but it is getting errors saying INSERT statement is wrong. I have no idea about MS access insert statement. i am totally tired of this. Please someone help me.

    Hello,
    MS Sql can cause problems where it goes off standard, however I dont think insert is any different.
    INSERT INTO table_name (column1, column2) VALUES (variable1, variable2)
    Make sure your table and column names are exactly right, Java is case sensitive, so make sure the case is correct also.
    The other common error is if you have a required field in the database that is not populated by your program, so, if for instance there was a column3 in the table for the above example, which was a required field, the sql would fail as there is no data being entered for column3.

  • INSERT statement with JSP

              Does anyone know how to create an INSERT statement with JSP using
              variables??
              I can do the insert if I code the values of the variables in the statement,
              but when I try to use variables to do the insert it tries to insert the
              variable name and not the value of the variable into the table.
              Thanks,
              Doug
              

    "Doug Schaible" <[email protected]> wrote in message news:<bicO7.1279268$[email protected]>...
              > I can do the insert if I code the values of the variables in the statement,
              > but when I try to use variables to do the insert it tries to insert the
              > variable name and not the value of the variable into the table.
              Doug,
              I think you missed the <%= blahblah %> syntax.
              Regards
              drit
              

  • Oracle table(s) data to INSERT(String) statements with JAVA

    Hi,
    How can I get sql inserts from a oracle table with JAVA?
    Is there a Oracle API for it?
    I need to store it in a file, the result file should have these examples lines:
    -- INSERTING into TEST
    Insert into "TEST" ("CODE","FAMILY","SUB_FAMILY","SEVERITY","STATUS","ANOMALY_DATE","DESCRIPTION",
    "COMMENTS","VALUE0","VALUE1","VALUE2","VALUE3","VALUE4","VALUE5","VALUE6","VALUE7","VALUE8",
    "VALUE9") values (1,'family1','subFamily11','bad','initial',to_date('0005-11-21','DD/MM/RR'),'someDescription',
    'someComment','someValue','someValue','someValue','uselessValue','uselessValue',null,null,null,null,null);
    the example line was created with the export tool from Oracle SQl developer
    Thks.
    Francisco

    user9046632 wrote:
    Hi Guys, this is me Francisco that wrote the first question, but now I've an NEW account. I'll try to explain it. For a Job I need a .txt file that contains the SQl string inserts from an Oracle Table. I can't use a Software because I need to do it with Java Code. I'm not trying to get the inserts's logging , I need a to export it from a table.I read One way to do it is using DataPump utility, but using this tools, will I get a text file? I read that DataPump works with binaries files. using Java JDBC and metadata, I need to convert all in String file, ok for it I'm agree, but I have to write a lot of code to know what kind of type I get from the Table to parse it. One example is with Date types, oracle softwares parse it as to_date('0005-11-21','DD/MM/RR') and java toTostrig will do it something like '2009-1-25 13:00:00'. Java toString method will truncate some Number types So I need to know if someone did it or give or can help me.
    Thank you very much. Francisco
    Again, explain the business problem you are trying to solve, not the technical one. WHY do you need a text file that contains "SQL string inserts"? It sounds very much like you are looking at your problem "through the wrong end of the telescope" and thus finding a poorly designed solution. But unless we know the real problem to be solved, it's hard to say any more than that this smells bad.
    Sorry about my English, it's not my natural language

  • Query in Insert statement with JDBC Rx adapter

    Hi,
    This is a FILE to JDBC scenario.
    My target datatype is like this with sample payload values
    statement_s
    statement_s
       action='INSERT"
      access
        A=1234
        B=1002
    key
       A=1234
       B ="10%"
         compareOperation= LIKE
    A(1..1) is primary key in DB and B(0..1) colunm is an optional one.
    I want to know if such kind of Insert query with(LIKE operator) is possible.
    Please reply me ASAP.
    Edited by: ram pranav on Feb 18, 2009 10:28 PM

    Hi Ram,
    IN case of "UPDATE_INSERT", you can use the KEY tag in your structure. Also you can provide LIKE as an attribute to the KEY element as follows :
    <key1>
         <col4 compareOperation=u201DLIKEu201D>val%</col4>
    </key1>
    But when you are trying to insert the data_, the <key> tags will be ignored and only <access> will be considered._
    action=UPDATE_INSERT
    The statement has the same format as for the UPDATE action. Initially, the same action is executed as for UPDATE. If no update to the database table can be made for this action (the condition does not apply to any table entry), values of the table described in the <access> element are inserted in accordance with the description of the action INSERT. <key> elements are ignored in this case.
    The response document has the following format; one of the two values is always 0 because either an UPDATE or an INSERT action is always executed:
    Go through the link I have provided earlier.
    Thanks,
    Pooja Pandey

  • Insert statement with Date, time into Oracle

    Hi,
    I've got the following statement that I'm trying to insert into Oracle. Actually had to change up the format to dd-mm-yy to get it to insert the date correctly, not sure why, but I've got it "supposedly" formatted to also insert the hours, min., seconds into the db record, but it's not catching it.
    My code:
    INSERT INTO VOTETBL
    (CHANGE_CTRL_ID,BUSVP,BRANCH,VOTE,VOTE_TIMESTAMP)
    VALUES (?, ?,?,?,to_date(sysdate, 'dd-mm-yy hh24:mi:ss'));Shouldn't the sysdate capture all those elements sufficiently? The day, month, year get inserted correctly with this, but not so for the time portion.
    Any suggestions is welcomed.
    Thx.

    ok, thanks.
    I tried making a result set with the following:
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ResultSet rst = stmt.executeQuery("select to_char(sysdate) from dual");
    Date dualtimestamp = (rst.getDate("sysdate"));But it makes the servlet blow up! Not sure why either, because if I enter that exact statement in Oracle, it pulls back the date and time just like I aim to. But not embedded in the result set statement within the servlet.
    It breaks up somehow and doesn't get that result!

  • Insert statement with timezone asking for parameter

    I have an insert statement in a file.
    When the whole file is executed it inserts around 300 rows in to table.
    One of the insert statement is failing. This insert statement inserts a query into column of a table.
    It is as following
    Insert into hr.TABLE_PATH
    (PATH, TABLE_OWNER_NAME, TABLE_NAME, PATH_NAME, TABLE_ACCESS_PATH_DESC, TABLE_PATH_SQL_TXT, PROCESS_CODE, DELETE_IND, ACCESS_ID)
    Values
    (290, HR, EMPLOYEES, 'Reconc', 'XYZ', 'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )', 'N ', 'N', 2);
    The problem is with this piece of insert:
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, 'GMT') AT TIME ZONE 'US/Central', 'YYYY-MM-DD HH24:MI:SS.FF6'), 'YYYY-MM-DD HH24:MI:SS.FF6') AS product_tmstp
    : --> is being considered as parameter.
    Where as the whole sql thing needs to get inserted into the table.

    If you are inserting a string, then any quotes inside the string should be replaced with two single quotes,
    try this,
    INSERT INTO hr.TABLE_PATH (PATH,
                               TABLE_OWNER_NAME,
                               TABLE_NAME,
                               PATH_NAME,
                               TABLE_ACCESS_PATH_DESC,
                               TABLE_PATH_SQL_TXT,
                               PROCESS_CODE,
                               DELETE_IND,
                               ACCESS_ID)
    VALUES (
             290,
             HR,
             EMPLOYEES,
             'Reconc',
             'XYZ',
             'SELECT COUNT(*) FROM (SELECT hr.product, TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp FROM ( SELECT DISTINCT(product) FROM hr.updated_table) upr, RH.product AS OF SCN :1 spr, RH.milestone AS OF SCN :1 sm WHERE spr.product = upr.product AND sm.product = spr.product MINUS SELECT prf.product, mi.product_tmstp FROM ( SELECT MAX(execute_id) exeute_id FROM hr.slave_execute ) cmr, hr.prod prf, hr.hr_info mi WHERE prf.execute_id = cmr.execute_id AND mi.milestone_group_id = prf.milestone_group_id )',
             'N ',
             'N',
             2
           );Note the
    TO_TIMESTAMP (TO_CHAR (FROM_TZ (sm.product_tmstp, ''GMT'') AT TIME ZONE ''US/Central'', ''YYYY-MM-DD HH24:MI:SS.FF6''), ''YYYY-MM-DD HH24:MI:SS.FF6'') AS product_tmstp First off, How are you inserting the data? using sqlldr or utl_file?
    If you are inseting using a script from Sqlplus
    use
    SET DEFINE OFFjust to make sure nothing is treated as a parameter.
    G.
    Edited by: Ganesh Srivatsav on Apr 6, 2011 5:20 PM

  • Insert statement with loop function

    Hello all,
    I'm new with the loop function
    What need to do is to use a select statement with a condition
    This output needs to be inserted in a table
    The values of the condition are stored also in a table
    It will be something like this:
    BEGIN
      FOR i IN (select nrs from table1)  LOOP
        INSERT INTO table_out_loop
        SELECT * FROM bigtable_vw
        WHERE nr = i
      END LOOP ;
    END ;
    I cant use a direct insert_into function in this case so I need the plsql to 'look' for the values 1 by 1 from the table1
    Any help would be appreciated

    Can't you just:
        insert into table_out_loop
        select *
        from   bigtable_vw
        where  nr in (select nrs from table1);
    If not, then post a better example and/or rephrase the question...

  • Creating Multiple INSERT statements with SQL

    is there a way to create multiple INSERT staements with SQL .
    Example scenario : This is only example but i have lot of data in the real time.
    sql : Select Emplid from Table A where Emplid between 100 and 350 will retun me 50 rows . i want to insert those rows into another table.
    I am looking for output like below instead of Giving output just as EMPLIDs
    Insert into PS_LM_DATA ( EMPLID ) values ( 123 )
    Insert into PS_LM_DATA ( EMPLID ) values ( 234 )
    Insert into PS_LM_DATA ( EMPLID ) values ( 334 )
    and so on....
    thanks ,
    Karu

    If you are inserting into another table, you could use
    insert into PS_LM_DATA ( EMPLID ) 
    select Emplid from Table A where Emplid between 100 and 350Example:
    SQL> insert into emp2(empno) select empno from emp;
    14 rows created.
    SQL> insert into emp2(empno) select empno from emp where empno between 7369 and 7788;
    8 rows created.

  • 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

  • Writting a SQL statement with Java

    Hello,
    I would like to perform an interrogation of my database but I have some trouble... here is the code I use (with MySQL) :
    String requete = "SELECT * FROM produit WHERE NomChimique ='butanol'";
    rs = stmt.executeQuery (requete); With this requete I find the record I have in my db. But with the following string the record is not found String requete = "SELECT * FROM produit WHERE NomChimique ='(+)-2-BUTANOL'";What I have not understand ?
    Thank you for your help,
    Jean-Marie

    I perform a first SELECT statement without WHERE,
    then I copy and past the value of the two exemples I
    give, the first succed, the second not...
    I am a little bit disappointed
    Jean-Marieyou should only be disappointed in yourself. this is NOT a Java problem. this is a Jean-Marie problem.
    one of the following is true...
    - the record does not exist
    - you are fouling up the result set handling and not noticing the record
    - something is going wrong with your query parsing
    So...
    make sure it exists.
    make sure you are connecting to the database you think you are.
    check over your result set code
    use preparedstatements
    ff all those fail then post your code (USING THE CODE TAGS) and someone will be delighted to help.

  • Error Running SQL Insert Statement with & in it

    Eclipse: 3.5 Galileo on Window Vista
    OEPE: 11gR1 11.1.14
    I get "invalid character" error when running this query in Eclipse:
    INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take&ndash;out joint can compare!', 1);
    I've tried multiple ways trying to escape the & character, but nothing worked. What is the right way of executing SLQ via OEPE plugin that have special characters in them.
    FYI, the following worked fine in Oracle 10g iSQL*Plus:
    SET DEFINE ~;
    INSERT INTO RECIPE (recipeId, name1, name2, recipeCategoryId) VALUES (2, 'Chunky Chicken Egg Rolls', 'No take&ndash;out joint can compare!', 1);
    Thanks,
    Dmitri.

    Very interesting case. I tried your insert stmt and got the same error. I finally got it to work by removing the ";" in the end. It looks like the jdbc driver choked up while there is ";" in the middle of the pl/sql statement and ";" in the end. If you remove ";" in the "No take&ndash;out joint can compare!" string and leave the ";" in the end, it also works!
    I don't quite understand why Oracle JDBC dirver behaves like that. I'll investigate it more and we may need to do some preprocessing on the pl/sql statement before sending it to the driver. At the mean time, just remove the ";" in the end if your string literal contains ";".
    Please let me know whether this workaround works for you. Thanks!
    Shenxue

  • Insert statement with using the value in struct

    Would like to clarify, i use cursor for selecting data from tableA and fetch the cusor into a struct. So the struct is holding all my data then i would like to insert all this data into tableB. Can i direct insert the data with the stuct?
    eg: INSERT INTO tableB VALUES (:mystruct);

    See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#i20479
    chapter Inserting PL/SQL Records into the Database
    BTW Update you should use cautiously, not to update all PKses and FKses see http://www.oracle-developer.net/display.php?id=418 for some examples.
    Gints Plivna
    http://www.gplivna.eu

  • QUESTION ON INSERT STATEMENT WITH SELECT

    Hi
    I have a table which contains three fields
    Table name : USERS
    ID NUMBER(10),
    NAME VARCHAR2(50),
    EMAIL VARCHAR2(50)
    SEQUENCE by name SEQ_ID
    I am trying to insert values into USERS from EMPLOYEE by virtue
    of insert into USERS (SELECT NAME, MAIL from EMPLOYEE) but i
    want to have one id for all the rows fetched from my inner
    query.
    I would like to know if here is a way, by which i can fetch a
    constant in my select statement which is not present in the
    table and use it like
    insert into USERS ( SELECT constant, NAME, MAIL FROM EMPLOYEE );
    where constant is some number unique for a given insertion.
    Thanks
    Arun

    Why not just try it? All you had to do was type
    insert into USERS SELECT 1, NAME, MAIL FROM EMPLOYEE ;
    and you would have had your answer immediately instead of
    waiting for me to tell you.
    rgds, APC

  • Insert Statement with Where Clause

    I m using this but giving error "Encounter the Symbol "Where" when expecting one of the following.
    Code is :-
    insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
    values (:sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3)
    where :sizecost.cost_no := :costmain.cost_no;

    Something like this ?
    insert into dum (cost_no, c_size, cmt1, cmt2, cmt3)
    select :sizecost.cost_no, :sizecost.c_size, :bottomcost.cmt1, :bottomcost.cmt2, :bottomcost.cmt3
    from dual
    where :sizecost.cost_no := :costmain.cost_no;Nicolas.
    : all these are items on form Ok, why not try to use the Form Forum ?
    Message was edited by:
    N. Gasparotto

Maybe you are looking for