我一直在尝试使用preparedStatement来选择数据并传递这些参数,但是出现了异常。
有谁能帮助我吗?以下是我的代码。
Connection connection = DBConnection.getConnection();
String query = "select * from integrantes where nome like '?' or rm like '?'";
ArrayList<Integrante> list = new ArrayList<>();
try {
PreparedStatement preparedStatement = connection.prepareStatement(query);
preparedStatement.setString(1, ('%' + term + '%'));
preparedStatement.setString(2, ('%' + term + '%'));
JOptionPane.showMessageDialog(null, ((OraclePreparedStatement) preparedStatement).getOriginalSql());
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
list.add(new Integrante(resultSet.getInt(1), resultSet.getString(2), resultSet.getString(3), resultSet.getInt(4)));
}
} catch(SQLException e) {
JOptionPane.showMessageDialog(null, "Erro ao listar o(s) integrante(s)." + e);
} catch(NullPointerException e) {
JOptionPane.showMessageDialog(null, "Ocorreu um erro inesperado.");
} catch(Exception e) {
JOptionPane.showMessageDialog(null, "Ocorreu um erro no código.");
}
return list;
id_grupon
是rm
列的别名)。 - Justin Cave