I’m having a trouble when retrieving in a very simple SELECT query.
I’m trying to retrieve all information from table ‘db_con_type’ and put them in array String of dbChoices.
Database:
The Select query works fine in report designer. Sorry i can’t upload the images since i’m new here.
Code:
public void setDbTypeChoices()
{
try
{
con2db connect2db = new con2db();
con = connect2db.aksesDatabase();
stmt = con.createStatement();
String sql = "SELECT * FROM db_con_type";
rs = stmt.executeQuery(sql);
int i = 0;
while(rs.next())
{
this.dbChoices[i] = rs.getString("DB_Type");
i++;
}
rs.close();
stmt.close();
ps.close();
con.close();
//Close Connection
connect2db.tutupKoneksi();
}
catch(Exception e)
{
System.out.println("SQL ERROR 1 = " + e.getMessage());
System.out.println("SQL ERROR 2 = " + e.toString());
}
}
Error:
SQL ERROR 1 = null
SQL ERROR 2 = java.lang.NullPointerException
Question:
Any idea what is happening? Any Solution?
Thanks
By the way, it is a good practice that if you are handing
ResultSetthat you first check if the result set returned is not null before operating on it e.g.rs.next()which will give you a NPE ifrsisnull.