⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tryencapsulatedmapping.java

📁 非常好的java事例以及带源码事例的java2教程
💻 JAVA
字号:
import java.sql.*;

public class TryEncapsulatedMapping
{
  public static void main (String[] args)
  {
    TryEncapsulatedMapping SQLtoJavaExample;
    try
    {
      SQLtoJavaExample = new TryEncapsulatedMapping();
      SQLtoJavaExample.listAuthors();
    }
    catch(SQLException sqle)
    {  System.err.println(sqle);  }
    catch(ClassNotFoundException cnfe)
    {  System.err.println(cnfe);  }
  }

  public TryEncapsulatedMapping() throws SQLException, ClassNotFoundException
  {
    Class.forName (driverName);
    connection = DriverManager.getConnection(sourceURL, user, password);
  }

  public void listAuthors() throws SQLException
  {
    Author author;

    String query = "SELECT authid, lastname, firstname, address1,"+
                   "address2, city, state_prov, postcode, country,"+
                   "phone, fax, email FROM authors";

    Statement statement = connection.createStatement();
    ResultSet authors = statement.executeQuery(query);



    while(authors.next())
    {
      System.out.println("\n" + Author.fromResults(authors));
    }
    authors.close();
    connection.close();
  }

  Connection connection;
  String driverName = "sun.jdbc.odbc.JdbcOdbcDriver";
  String sourceURL = "jdbc:odbc:technical_library";
  String user = "guest";
  String password = "guest";
}

⌨️ 快捷键说明

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