Home > Back-end >  PreparedStatement placeholders in the SQL statement is there a number of restrictions
PreparedStatement placeholders in the SQL statement is there a number of restrictions

Time:03-03

The Connection conn=getConncetion ();
String SQL="insert into account (account_id, recommender_id, login_name login_password, status, create_date, pause_date, close_date, real_name, idcard_no, birthdate, and gender, telephone) values (1 account_seq nextval,? ,? ,? , '0', sysdate, null, null,? ,? The to_date (? , '- dd yyyy - mm),? ,?) ";
System. The out. Println () Statement. The RETURN_GENERATED_KEYS;
PreparedStatement STMT=conn. PrepareStatement (SQL, new String [] {} "account_id");
System. The out. Println (" 99999999999999 ");
C=Calendar Calendar. GetInstance ();
C.s. etTime (the getBirthdate ());
Be sad et chtistina georgina rossetti.british poetess String birth=(. Calendar YEAR) be sad et chtistina georgina rossetti.british poetess + "-" + (Calendar. The MONTH) + "-" be sad et chtistina georgina rossetti.british poetess + (Calendar. The DATE);
STMT. SetInt (1, the getRecommenderId ());
STMT. SetString (2, the getLoginName ());
//STMT. SetString (3, birth);

STMT. SetString (3, the getLoginPassword ());
STMT. SetString (4, the getRealName ());
STMT. SetString (5, the getIdcardNo ());
STMT. SetString (6, birth);

STMT. SetString (7, the getGender ());
STMT. SetString (8, the getTelephone ());
STMT. ExecuteUpdate ();
The ResultSet rs=STMT. GetGeneratedKeys ();
Rs. The next ();
Int id=rs. Get int (1);
The setAccountId (id);
At this point would be an error:
The Exception in the thread "main" Java. Lang. ArrayIndexOutOfBoundsException: 8
At oracle.jdbc.driver.OracleSql.com puteBasicInfo OracleSql. Java: (950)
At oracle, the JDBC driver. OracleSql. GetSqlKind (OracleSql. Java: 623)
At oracle, the JDBC driver. OraclePreparedStatement. & lt; init> (OraclePreparedStatement. Java: 1212)
At oracle, the JDBC driver. T4CPreparedStatement. & lt; init> (T4CPreparedStatement. Java: 28)
At oracle, the JDBC driver. T4CDriverExtension. AllocatePreparedStatement (T4CDriverExtension. Java: 68)
At oracle, the JDBC driver. PhysicalConnection. PrepareStatement (PhysicalConnection. Java: 3059)
At oracle, the JDBC driver. PhysicalConnection. PrepareStatement (PhysicalConnection. Java: 2961)
At oracle, the JDBC driver. PhysicalConnection. PrepareStatement (PhysicalConnection. Java: 5940)
At org.apache.com mons. DBCP. DelegatingConnection. PrepareStatement (DelegatingConnection. Java: 482)
At org.apache.com mons. DBCP. PoolingDataSource $PoolGuardConnectionWrapper. PrepareStatement (PoolingDataSource. Java: 409)
At com.tarena.net ctoss. Impl. AccountDAOImpl. Save (AccountDAOImpl. Java: 58)
At com.tarena.net ctoss. TestAccountDAO. TestSave (TestAccountDAO. Java: 49)
At com.tarena.net ctoss. TestAccountDAO. Main (TestAccountDAO. Java: 19)


But there is no problem after removing a placeholder

Then it turned regular after he SQL statements to the following
String SQL="insert into account (account_id, recommender_id, login_name login_password, status, create_date, pause_date, close_date, real_name, idcard_no, birthdate, and gender) values (1 account_seq nextval,? ,? ,? , '0', sysdate, null, null,? ,? The to_date (? , '- dd yyyy - mm),?) ";
  • Related