thinking in Java书中 的源代码

源代码在线查看: lookup.java

软件大小: 355 K
上传用户: Fiona1207
关键词: thinking Java in 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				//: c15:jdbc:Lookup.java
				// From 'Thinking in Java, 2nd ed.' by Bruce Eckel
				// www.BruceEckel.com. See copyright notice in CopyRight.txt.
				// Looks up email addresses in a 
				// local database using JDBC.
				import java.sql.*;
				
				public class Lookup {
				  public static void main(String[] args) 
				  throws SQLException, ClassNotFoundException {
				    String dbUrl = "jdbc:odbc:people";
				    String user = "";
				    String password = "";
				    // 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
				  }
				} ///:~			

相关资源