NullPointerException from createQuery()
I've searched the internet for about two hours now and all I can figure out is that this has something to do with the table I'm trying to query from. I have two other queries that I call and they work fine. I read someone else's problem where it was stopping part way through the query which tells me it's something to do with the table.
Here is the method calling the query
Code:
private void setTableInfo(Object cbContents)
{
System.out.println("Start");
int j = 0;
DefaultTableModel model;
ResultSetMetaData rsmd;
ResultSet rs;
try
{
System.out.println("Trying for data by sending\nSELECT * FROM report_tables.idle_report WHERE family='"
+ cbContents + "'");
rs = myApplication.connection.createQuery("SELECT * FROM report_tables.idle_report WHERE family='"
+ cbContents + "'");
System.out.println("Getting MetaData");
rsmd = rs.getMetaData();
System.out.println("Got the RS and MetaData");
model = (DefaultTableModel)tblActiveList.getModel();
model.setColumnCount(rsmd.getColumnCount());
System.out.println("Set the Column count to " + rsmd.getColumnCount());
}
catch(Exception e)
{
e.printStackTrace();
}
}
Here is the method that is being called
Code:
public ResultSet createQuery(String query)
{
try
{
Statement stat4 = conn.createStatement();
result = stat4.executeQuery(query);
}
catch(SQLException e)
{
JOptionPane.showMessageDialog(null, "Error in createQuery " + e);
}
return result;
}
Does anyone have any ideas why this error is being thrown or at least some common reasons?
EDIT: I did some more testing and found maybe I was wrong on my assumption it was the table. I tried using a query that I know works because I used it in the program previously and it worked. Seems now that it may be the method that is calling the query. Still need help though.