import java.sql.*;

public class Lookup {

public static void main(String[] args) {

String dbUrl = "jdbc:odbc:people";

String user = "";

String password = "";

try {

// Load the driver (registers itself)

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection c = DriverManager.getConnection( dbUrl, user, password);

Statement s = c.createStatement();

// SQL code: ResultSet r = s.executeQuery( "SELECT FIRST, LAST, EMAIL " + "FROM people.csv people " + "WHERE " + "(LAST='" + args[0] + "') " + " AND (EMAIL Is Not Null) " + "ORDER BY FIRST");

while(r.next()) {

// Capitalization doesn't matter:

System.out.println(r.getString("Last") + ", " + r.getString("fIRST") + ": " + r.getString("EMAIL") );

}

s.close(); // Also closes ResultSet

}

catch(Exception e) {

e.printStackTrace();

}

}

} ///:~

0 comments: