I ran in to a problem while trying to get data from my sql server where they give a null point exception at prepared statement. I'm sure this must be a noob question but please do help :)
this is the method i'm calling
public void notification(){
int MachCode = 1721;
try{
String sql ="Select TimeOn from PRODUCTIONS_MONITOR where MachCode='"+MachCode+"'";
pst = con.prepareStatement(sql);
rs = pst.executeQuery();
while(rs.next()){
arrCount.add(rs.getInt(1));
}
for(int i=0;i<arrCount.size();i++){
Count = Count + arrCount.get(i);
}
if(Count % 10 == 0){
System.out.println("Time = " + Count);
}
}catch(SQLException e){
e.printStackTrace();
}
}
and here is my db connection
public static Connection ConnecrDb() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://10.228.59.2:1433;databaseName=dbNautilus;user=SA;password=KreedaIntimo@2017;");
System.out.println("Connected to database !");
} catch (SQLException sqle) {
System.out.println("Sql Exception :" + sqle.getMessage());
} catch (ClassNotFoundException e) {
System.out.println("Class Not Found Exception :" + e.getMessage());
}
return null;
}