Friday, 6 September 2013

Cannot find the column after committed update (JDBC, MySQL)

Cannot find the column after committed update (JDBC, MySQL)

I stuck with a strange problem: I do SELECT query to the MySQL database,
commit UPDATE query and cannot do SELECT query again after it (Java
complains that couldn't find the column).
Here is my code:
//SELECT
dbhIrmdb.setAutoCommit(false);
PreparedStatement preparedSelect=null;
preparedSelect=dbhIrmdb.prepareStatement(query);
ResultSet rowSet=preparedSelect.executeQuery();
dbhIrmdb.commit();
while (rowSet.next()) {
computer=new ComputerInfo();
computer.setIndex(index); index++;
computer.setComputers_id(rowSet.getString("computers_id"));
....
}
dbhIrmdb.setAutoCommit(true);
//UPDATE
PreparedStatement commonUpdate=null;
try {
String queryUpdate="UPDATE computers SET name=?, serial=?,
inv_number=?, comments=?, rack_unit=?, box_unit=?, ram=? WHERE
ID="
+currentComp.getComputers_id();
dbhIrmdb.setAutoCommit(false);
commonUpdate=dbhIrmdb.prepareStatement(queryUpdate);
commonUpdate.setString(1, currentComp.getComputers_name());
commonUpdate.setString(2, currentComp.getComputers_serial());
commonUpdate.setString(3, currentComp.getComputers_inv_number());
commonUpdate.setString(4, currentComp.getComments());
commonUpdate.setString(5, currentComp.getComputers_rack_unit());
commonUpdate.setString(6, currentComp.getBox_unit());
commonUpdate.setString(7, currentComp.getRam());
commonUpdate.executeUpdate();
dbhIrmdb.commit();
} catch (SQLException ex) {
ex.printStackTrace();
try {
System.err.print("Transaction is being rolled back");
dbhIrmdb.rollback();
} catch(SQLException excep) {
excep.printStackTrace();
}
}
finally {
if (commonUpdate != null) {
commonUpdate.close();
}
dbhIrmdb.setAutoCommit(true);
}
I did deep research through the site, but I couldn't find such case.
I'd be appreciate for any help or advice.

No comments:

Post a Comment