我正在编写一个用户必须登录的程序。我已经一次又一次地查看了我的代码,但我一直得到“null”作为错误。这不仅适用于部分程序的登录,也适用于用户可以创建帐户的部分。基本上,无论我在哪里实现JDBC,都会弹出“null”错误。我该如何解决这个问题?
String user_name_check = user_name.getText().trim();
char[] pass = password_enter.getPassword();
String password_check = Arrays.toString(pass);
String query = "SELECT * FROM USER_INFO WHERE USERNAME = '" + user_name_check + "';";
try{
rs = st.executeQuery(query);
if(rs.next()){
//changing the panel (start)
if(password_check.equals(rs.getString("PASS"))){
MAIN.removeAll();
MAIN.add(news_feed);
MAIN.repaint();
MAIN.revalidate();
//changing the panel (end)
//giving values to class level field variables (start)
username = user_name_check;
firstname = rs.getString("FIRST_NAME");
lastname = rs.getString("LAST_NAME");
dob = rs.getString("DOB");
gender = rs.getString("GENDER");
bio = rs.getString("BIO");
home_user_name.setText(username);
set_dp(home_user_dp, username);
}
}
else sign_in_message.setVisible(true);
}
catch(Exception e){
System.out.println(e.getMessage() + " @jButton2ActionPerformed SIGN IN");
}
错误:null @ jButton2ActionPerformed SIGN IN
修改
这是JDBC连接方法:
public void JDBC_Connect(){
try{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost/socialnetwork", "root", "mukundrox");
st = con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage() + " @JDBC_connect");
}
}