我得到一个空指针异常。我不知道为什么我得到它?这是我得到Exception“perst = 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);
答案 0 :(得分:4)
你有
strURL = "jdbc:mysql://localhost:3306/ColdStorage? zeroDateTimeBehavior=convertToNull";
删除网址中的空格。如果做不到这一点,请仔细检查它是否是正确的URL和用户名/密码,以及确保在包含的库中有mysql连接器JAR。