Mysql JDBC, key key to write record set
In addition to the previous mysql limit, it is found that in the JDBC programming, the code is as follows, if you press ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updatable open record set, the Resultset is UPDATE or INSERT, but In this manner in MySQL, this operation will throw an Exception, saying that the recordset cannot be modified (at least one of a primary key), so it is possible to establish a primary key on the table.
Nothing test ADO MYSQL, nor did it test the JDBC other databases. In fact, for simple modifications and addition operations, I prefer to call the Update / INSERT SQL statement directly instead of opening the recordset operation.
public boolean AddOrUpdateCurrPrice (int nPrice) {try {String query = "SELECT * FROM futures_current_price WHERE product =?"; PreparedStatement stmt = oConn .prepareStatement (query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
Stmt.setString (1, Sproduct); ResultSet RS = stmt.executeQuery (); Boolean Badd = false; if (rs.last ()) {debugprint ("Update");} else {debugprint ("add"); RS .MOVETOINSERTROW (); rs.UpdateString ("Product", Sproduct); Badd = true;} rs.UpdateString; rs.UpdateInt ("Price", nprice); if (badd) rs.inSertrow (); Else ket ();
Rs.close (); stmt.close (); return true;} catch (exception e) {debugprint ("fPRICE ERROR" E.getMessage ()); return false;}}