0

I'm very new to working with SQL stuff in Java, I'm trying to select a view I made in Oracle and print off it's contents, but I get a nullpointerexception

try {
            conn = DriverManager.getConnection(dbURL, user, password);
            conn.clearWarnings();
            System.out.println("Connection opened! for driver ==>Oracle 11XE");
            while (!option.equalsIgnoreCase("X"))
            {
                System.out.print("What to do Q1 (1) Q2 (2) or (X) exit: ");
                option = s.nextLine();
                System.out.println("");

                if (option.equalsIgnoreCase("1"))
                {
                    System.out.println("ID      Product Name          Price");
                    System.out.println("==      ============          =====");
                    ResultSet rs = stmt.executeQuery("select * from VQ1");

                    while (rs.next()){
                        System.out.println(rs.getString("PRODUCTID") + "     " + rs.getString("PRODUCTNAME") + "          " + rs.getString("UNITPRICE"));
                    }
                    rs.close();
                }
            }

The exception occurs at ResultSet rs = stmt.executeQuery("select * from VQ1")

Like I said, I'm really new to working with this kinda stuff, so it could be something extremely small and simple.

Frankjoww
  • 45
  • 5

1 Answers1

0

You never initialized stmt - It's null. You are missing:

    stmt = conn.createStatement();
pczeus
  • 7,195
  • 4
  • 34
  • 50