0

I am trying to make a query on my GUI through a database, adding to the database is fine, but making a query through the GUI gives me a

"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" error

and I cannot figure out why. 4th line here is the first error it is giving me.

String category=categories[searchCategory];

    try {
        PreparedStatement stmnt = null;
        stmnt = con.prepareStatement("SELECT * FROM Jobs WHERE " +category + 
" LIKE '%?%')");
        stmnt.setString(1,searchingFor);
        System.out.println(stmnt.toString());
        ResultSet result = stmnt.executeQuery();
        while (result.next()) {
            for (int i=0; i<categories.length; i++){
                String field=categories[i];
                System.out.println(result.getString(field));
            }



        }
    } catch (SQLException e) {

        System.out.println("Error during select query " + e);
        e.printStackTrace();
    }


}

This is the createSearchTab code that it is saying i have an error at.

excelReader.search(category, searchingFor);

where is the NullPointerException?

FortyTwo
  • 2,414
  • 3
  • 22
  • 33
  • 1
    Hard to know exactly if you dont post the exception trace, so please post it. Its probably likely that `con` is null. if the 4th line is where you get the error. – astrade Jul 20 '17 at 15:19
  • Hi and welcome to Stack Overflow, please take a time to go through the [welcome tour](https://stackoverflow.com/tour) to know your way around here (and also to earn your first badge), read how to create a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and also check [How to Ask Good Questions](https://stackoverflow.com/help/how-to-ask) so you increase your chances to get feedback and useful answers. – DarkCygnus Jul 20 '17 at 15:32
  • @astrade It is null, i am fairly new to coding, what would i put in the pllace for "null"? – Drew Blankenship Jul 20 '17 at 16:56

0 Answers0