私のメソッドはmy から取得する必要がusername
あります:password
admintable
MySql コンソールの私のテーブル:
私の方法:
public void adminEnterCondition(){
Connection con;
PreparedStatement preparedStatement;
ResultSet resultSet;
String query = "select * from admintable";
String username,password;
try {
con= DriverManager.getConnection(...);
preparedStatement = con.prepareStatement(query);
resultSet = preparedStatement.executeQuery();
username = ...
password = ...
}
catch (SQLException sqle){
sqle.printStackTrace();
}
}
アップデート:
私はこれを試します:
public void adminEnterCondition() {
Connection con;
PreparedStatement preparedStatement;
ResultSet resultSet;
String query = "select * from admintable";
String username = null, password = null;
try {
con = DriverManager.getConnection(...);
System.out.println("Connected");
preparedStatement = con.prepareStatement(query);
resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
username = resultSet.getString(username);
password = resultSet.getString(password);
}
System.out.println(username);
System.out.println(password);
} catch (SQLException sqle) {
sqle.printStackTrace();
}
}
しかし、この例外が発生します:
Connected
Exception in thread "main" java.lang.NullPointerException
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1176)
at java.lang.String$CaseInsensitiveComparator.compare(String.java:1170)
at java.util.TreeMap.getEntryUsingComparator(TreeMap.java:369)
at java.util.TreeMap.getEntry(TreeMap.java:340)
at java.util.TreeMap.get(TreeMap.java:273)
at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1072)
at com.mysql.jdbc.ResultSetImpl.getString(ResultSetImpl.java:5488)
at test.GetCellvalue.adminEnterCondition(GetCellvalue.java:26)
at test.GetCellvalue.main(GetCellvalue.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)