SQL statements in Java
Posted on 2004-08-26
Hello. I'm writing a test program that connects to my sample Northwood database that comes with SQL Server. Here is the code, and I'll describe the error after:
public static Connection con;
public static Statement stmt;
public static String url = "jdbc:odbc:Northwind";
public static void main (String args)
Driver d = (Driver)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection con = DriverManager.getConnection(url,
String query = "select Password from Employees where LastName = 'Doe'";
ResultSet rs = stmt.executeQuery(query);
String s = rs.getString("password");
I'm getting a NullPointerException at the line with ResultSet rs = stmt.executeQuery(query). Any tips?
p.s. on the line String s = rs.getString("password"), I'm pretty sure I can just put 0 instead of "password". Is this correct if I'm just pulling one value?