Reputation: 651
i am getting a null pointer exception.i don't know the reason why am i getting it? This is the sentence where i am getting Exception "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");
}
i have a dbhandler file which has the connection string whose code i have attached here.
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);
Upvotes: 0
Views: 308
Reputation: 1600
You have
strURL = "jdbc:mysql://localhost:3306/ColdStorage? zeroDateTimeBehavior=convertToNull";
Remove the space in the URL. Failing that, double check if it is the correct URL and your username/password, as well as make sure you have the mysql connector JAR in your included libraries.
Upvotes: 4