我写了这个查询,但是有错误。
String x = String.valueOf(jTable1.getModel().getValueAt(row, 2) );
try {
PreparedStatement preparedStatement1 = connection.prepareStatement("select sportman_code, "
+ "customer_code from sportman where sportman_code = ?");
preparedStatement1.setString(1, x);
preparedStatement1.executeUpdate();
} catch (Exception e) {
System.out.print(e.getMessage());
}
这是错误
Can not issue executeUpdate() for SELECTs
什么是问题?
答案 0 :(得分:3)
尝试
ResultSet resultSet = preparedStatement1.executeQuery();
而不是
preparedStatement1.executeUpdate();
resultSet = preparedStatement.executeQuery();
答案 1 :(得分:1)
要发出SQL SELECT,您必须使用executeQuery而不是executeUpdate。我也看到;
在那里闲逛。