4 Replies Latest reply on Apr 4, 2008 7:54 AM by 592250

    error in insert query

    630032
      stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
      String query =
      "insert into log1(converted_time,elapsed_time,client_ip,status_code,data_received,request_method,url,lookup_info,host_ip,object_type,system_time)values("+Fields[0]+","+Fields[1]+","+Fields[2]+","+Fields[3]+","+Fields[4]+","+Fields[5]+","+Fields[6]+","+Fields[7]+","+Fields[8]+","+Fields[9]+","+Fields[10]+")";
      System.out.println("\nExecuting query : "+query);
      rset = stmt.executeQuery(query);
      System.out.println("data inserted");



      this is the error i get


      Executing query : insert into log1(converted_time,elapsed_time,client_ip,status_code,data_received,request_method,url,lookup_info,host_ip,object_type,system_time)values(Sun Mar 23 04:40:35 IST 2008,2765,66.79.165.92,TCP_MISS/200,18335,CONNECT,207,-,DIRECT/207.200.94.12,-,1206227433.960)
      java.sql.SQLException: SQL string is not Query
        • 1. Re: error in insert query
          414247
          The driver is telling you the truth. Queries are 'select ...'

          Use executeUpdate() for insert, delete, update etc.
          • 2. Re: error in insert query
            630032
            java.sql.SQLException: Listener refused the connection with the following error:
            ORA-12519, TNS:no appropriate service handler found
            The Connection descriptor used by the client was:
            172.16.40.4:1521:ORCLDEMODB


            This is the error i getr when i run the query below
            getDBConnection();

                 stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
                 // String query =
                 // "insert into logs(converted_time,elapsed_time,client_ip,status_code,data_received,request_method,url,lookup_info,host_ip,object_type,system_time)values("+Fields[0]+","+Fields[1]+","+Fields[2]+","+Fields[3]+","+Fields[4]+","+Fields[5]+","+Fields[6]+","+Fields[7]+","+Fields[8]+","+Fields[9]+","+Fields[10]+")";
                 // System.out.println("\nExecuting query : "+query);
            // System.out.println("hi="+rset);
            int query = stmt.executeUpdate(
            "insert into logs(converted_time,elapsed_time,client_ip,status_code,data_received,request_method,url,lookup_info,host_ip,object_type,system_time)values("+Fields[0]+","+Fields[1]+","+Fields[2]+","+Fields[3]+","+Fields[4]+","+Fields[5]+","+Fields[6]+","+Fields[7]+","+Fields[8]+","+Fields[9]+","+Fields[10]+")");

                 System.out.println("data inserted");
            • 3. Re: error in insert query
              630032
              getDBConnection();
              stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

              String input = "INSERT INTO LOGS (CONVERTED_TIME, ELAPSED_TIME, CLIENT_IP, STATUS_CODE, DATA_RECEIVED, REQUEST_METHOD, URL, LOOKUP_INFO, HOST_IP, OBJECT_TYPE, SYSTEM_TIME)VALUES("+Fields[0]+","+Fields[1]+","+Fields[2]+","+Fields[3]+","+Fields[4]+","+Fields[5]+","+Fields[6]+","+Fields[7]+","+Fields[8]+","+Fields[9]+","+Fields[10]+")";

              rset= stmt.executeQuery(input);



              // System.out.println("a="+Fields[10]);

              System.out.println("hi="+rset);
              System.out.println("data inserted");

              }
              catch ( SQLException e ) {

              System.out.println(e.toString());

              } }





              the error taht i get is
              java.sql.SQLException: SQL string is not Query
              sometimes i get

              java.sql.SQLException: ORA-00917: missing comma
              • 4. Re: error in insert query
                592250
                Write the whole statement in an texteditor like notepad and copy it into your java file in JDeveloper. The quotes (") will be made automatically.

                I also recommend that you use a StringBuilder to create your string, because each

                string += "newStringPart";

                or

                string = "newStringPart1" + "newStringPart2

                instantiates a new String object and the old one is still existing. So you will get a lot of Strings allocated that you do not need. The garbage collector should "destroy" them some time, but you cannot be sure when the gargabe collector does that.