我得到一个空指针异常。我不知道为什么我得到它?这是我得到异常“prest = conn.preparedstatemt(sql)”的句子。
conn = DBHandler.getDBConnection();
String nextOccid = "";
sql = "select nextOccId from ColdStorage.master_ids";
prest = conn.prepareStatement(sql);
ResultSet rs5 = prest.executeQuery();
while (rs5.next()) {
nextOccid = rs5.getString("nextOccId");
}
我有一个 dbhandler 文件,其中包含我在此处附加的代码的连接字符串。
public static Connection getDBConnection() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Connection conn = null;
String strUserID, strUserPwd, strURL = null;
try {
Class.forName("com.mysql.jdbc.Driver");
strUserID = "root";
strUserPwd = "";
strURL = "jdbc:mysql://localhost:3306/ColdStorage? zeroDateTimeBehavior=convertToNull";
conn = DriverManager.getConnection(strURL, strUserID, strUserPwd);