makingastatement.java

来自「Java Classic Examples是我买的两本书:《JAVA经典实例》和」· Java 代码 · 共 40 行

JAVA
40
字号
import java.sql.*;

public class MakingAStatement
{
  public static void main(String[] args)
  {
    // Load the driver
    try
    {
      // Load the driver class
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

      // Define the data source for the driver
      String sourceURL = "jdbc:odbc:technical_library";

      // Create a connection through the DriverManager 
      Connection databaseConnection = 
                                DriverManager.getConnection(sourceURL);

      Statement statement = databaseConnection.createStatement();

      ResultSet authorNames = statement.executeQuery(
                                       "SELECT lastname, firstname FROM authors");

      // Output the resultset data
      while(authorNames.next())
      System.out.println(authorNames.getString("lastname")+" "+
                                               authorNames.getString("firstname"));
    }
    catch(ClassNotFoundException cnfe)
    {
      System.err.println(cnfe);
    }
    catch(SQLException sqle)
    {
      System.err.println(sqle);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?