Home > Back-end >  Java database of small problem
Java database of small problem

Time:10-26

 
Public static ResultSet execute (Connection Connection, SQL, String Object [] params, ResultSet ResultSet, PreparedStatement PreparedStatement) throws SQLException {
preparedStatement=connection.prepareStatement(sql);
for (int i=0; i //setObject, placeholder starting from 1, but our array from zero to start!
PreparedStatement. SetObject (I + 1, params [I]);
}
The resultSet=preparedStatement. ExecuteQuery ();
Return a resultSet.
}

For the query above public class, but I remember I have been learning for () with a MySQL query statement does not need to this 3 line statements can query, execution of the SQL returns a result set, and then query information was obtained from the result set, this for around this have what, want detailed point,

CodePudding user response:

The variable assignment in preparedStatement, this function the value to the object array as a parameter to this function

CodePudding user response:

The easiest way is to see if your SQL USES? The question mark
Such as select * from TB where a=? And b=?
Here? On behalf of the need to SQL parameter, the for loop is to set these parameters, there are a few? There are several parameters, the length of params is the number of parameters, so use for take each params [I] to the appropriate? That preparesStatement generates SQL is the full version of SQL, SQL is equivalent to the original? Have replaced the real parameters,
  • Related