Java.sql.SQLException: Missing in or out parameter in index:: X

Source: Internet
Author: User

When using JDBC, there is an error: Java.sql.SQLException: The in or out parameter is missing from the index:: X

The following example Insertlog.execute (); This line throws the exception:

String logsql = "INSERT into tbl_obj (ID, obj, type, cont, proposer, operator, date, remark)"                       + "values (Seq_tot.nextva L,?,?,?,?,?, sysdate,?) "; Insertlog = Conn.preparestatement (logsql); insertlog.setstring (2, Trace.getobj ()); Insertlog.setstring (3, Trace.gettype ()); Insertlog.setstring (4, Trace.getcont ()); Insertlog.setstring (5, Trace.getproposer ()); Insertlog.setstring (6, Trace.getoperator ()); Insertlog.setstring (8, Trace.getremark ()); Insertlog.execute ();


Retrieved some posts, for this problem, pointed out a lot of reasons, " full-width half angle, too many parameters, the configuration file and database field type is inconsistent, or the database index problem, etc. ".

According to the error, and predecessors all kinds of wall, boils down to two points:

(1) Are there any problems with indexing? ("Missing in Index")

(2) Does the field assignment match the database field type?


For the argument (1), look at the index of this table, which is the primary key with ID, there is no other index, so there is only one primary key index, the view state is valid, there is no error:

Sql> Select Index_name, status from User_indexes where table_name= ' tbl_obj_trace '; index_name                     STATUS--------------------------------------sys_c0031302                   VALID


For the argument of (2),

First of all, the definition of the field type in the Set/get method of trace is a string, and the field type in the corresponding library is VARCHAR2, no difference.

Second, look at the setstring, and the values of the field is corresponding AH. In fact, the problem is here, look at the explanation of the SetString method:

void java.sql.PreparedStatement.setString (int parameterindex, String x) throws sqlexceptionsets the designated parameter to the given Java String value.  The driver converts this to a SQL VARCHAR or LongVarChar value (depending on the argument's size relative to the driver ' s Limits on VARCHAR values if it sends it to the database. Parameters:parameterindex The first parameter is 1, the second is 2If a database access error occurs or This method was called on a closed PreparedStatement

You can see the first parameter Parameterindex, the parameter index,Parameterindex does not correspond to a parameter marker in the SQL statement(if there is no Should be to the parameter identifier in the SQL statement), the SqlException exception is thrown.

Values in SQL statements (Seq_tot.nextval,?,?,?,?,?, sysdate,?) The parameter identifier is 6, SetString is also 6, but the order is not correct, the index number of the first parameter in SetString is consistent with the SQL statement, not the location of the Values field in the SQL statement. Instead, it should be the ordinal of the parameter identifier in the SQL statement values.

Change to the following format:

String logsql = "INSERT into tbl_obj (ID, obj, type, cont, proposer, operator, date, remark)"                       + "values (Seq_tot.nextva L,?,?,?,?,?, sysdate,?) "; Insertlog = Conn.preparestatement (logsql); insertlog.setstring (1, Trace.getobj ()); Insertlog.setstring (2, Trace.gettype ()); Insertlog.setstring (3, Trace.getcont ()); Insertlog.setstring (4, Trace.getproposer ()); Insertlog.setstring (5, Trace.getoperator ()); Insertlog.setstring (6, Trace.getremark ()); Insertlog.execute ();


Summarize:

JDBC This error, the message is very obscure, but this is the wrong feeling is the kind of touch once, the basic next time you can know the scope of the error, the troubleshooting should be more smooth, such as: The index is not a problem, the field type in the Code and the table field type is consistent, The parameter index used in the code and the parameter identifiers in the SQL statement are consistent (number, order, and so on).


Eof

Bisal @17jun15

??

??

Java.sql.SQLException: Missing in or out parameter in index:: X

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.