我正在尝试从数据库中获取数据,但什么都没得到。问题是
ResultSet resultSet = statement.executeQuery(readQuery);
总是空着的。并且
while(resultSet.next())
永远不会执行。 非常感谢任何帮助
public class DB {
public Connection connect() {
Connection connection = null;
try {
String databaseURL = "jdbc:derby://localhost:1527/DB;create=true;user=user;password=password";
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
connection = DriverManager.getConnection(databaseURL);
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException | SQLException ex) {
Logger.getLogger(DB.class.getName()).log(Level.SEVERE, null, ex);
}
return connection;
}
ArrayList read(Connection connection, String table, String column, String value) {
ArrayList results = new ArrayList();
Statement statement = null;
try {
statement = connection.createStatement();
String readQuery = "select * from " + table + " where " + column + " = '" + value + "'";
out.print(readQuery);
ResultSet resultSet = statement.executeQuery(readQuery);
while (resultSet.next()) {
ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
int numberOfColumns = resultSetMetaData.getColumnCount();
out.print("Read\n");
for (int i = 1; i < numberOfColumns + 1; i++) {
results.add(resultSet.getString(i));
}
}
statement.close();
connection.close();
}
catch (SQLException ex) {
}
return results;
}
}