Java statements for database operations are prone to errors. java statements are prone to errors.
Let's first look at the following statement
String sqlString = "select * from petMessage where petName = '" + pet. getPetName () + "';";
The preceding statement Selects all the information from the specified information. getPetName () respectively added a pair of "" to the left and right of the pair to connect to the string function, but carefully looked at the left and right of the pair, there is a symbol 'is the single quotation mark, the single quotation mark is used to enclose pet. the getPetName () Information keeps the SQL statement syntax accurate!
An error occurred while operating the database in java.
Your SQL statement is incorrect. A comma is added at the end.
SQL can be output in the console to check whether it is correct
Java SQL statement for saving data to the database
I feel that the problem is not very clear. Is a form containing only a group of name id sex information? It is also a table like excel, or csv format, which contains name id sex information of n people, each group is a row. Is there any information in the form not associated with the information in the database? It is purely the nth record in the database corresponding to the nth form or table. However, in any case, only one entry can be read from the form and inserted one by one. However, you can use the database's "batch Update" method and PreparedStatement to slightly improve the efficiency, for example,
String s = "insert into T2 (B, C, name, id, sex) values (?, ?, ?, ?, ?) "
PreparedStatement pst = conn. prepareStatement (s );
Rs_T = executeQuery ("select B, C from T ");
While (rs_T.next ()){
Pst. setString (1, rs_T.getString ("B "));
Pst. setString (2, rs_T.getString ("C "));
Pst. setString (3, name); // The name, id, and sex values are obtained in the form.
Pst. setString (4, id );
Pst. setString (5, sex );
Pst. addBatch ();
}
Pst.exe cuteBatch ();
However, this may not be what the landlord wants.