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

📄 trysimplemapping.java

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

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

  public TrySimpleMapping() 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())
    {
      int id            = authors.getInt(1);
      String lastname   = authors.getString(2);
      String firstname  = authors.getString(3);

      String[] address  = { authors.getString(4), authors.getString(5)};
      String city       = authors.getString(6);
      String state      = authors.getString(7);
      String postcode   = authors.getString(8);
      String country    = authors.getString(9);
      String phone      = authors.getString(10);
      String fax        = authors.getString(11);
      String email      = authors.getString(12);

      author = new Author(id, lastname, firstname,
                          address, city, state, postcode,
                          country, phone, fax, email);

      System.out.println("\n" + author);
    }
    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 + -