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

📄 filereader.java~24~

📁 完成一级汉字和二级汉字的按拼音排序和按笔画排序功能
💻 JAVA~24~
字号:
package net.bishe.file;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */
import java.sql.*; // JDBC package
import com.microsoft.jdbc.sqlserver.*;

public class FileReader {
  private java.sql.Connection con = null;
  private final String url = "jdbc:microsoft:sqlserver://";
  private final String serverName = "localhost";
  private final String portNumber = "1433";
  private final String databaseName = "pubs";
  private final String userName = "sa";
  private final String password = "";
  // Informs the driver to use server a side-cursor,
  // which permits more than one active statement
  // on a connection.
  private final String selectMethod = "cursor";

  private String getConnectionUrl() {
    return url + serverName + ":" + portNumber + ";databaseName=" +
        databaseName + ";selectMethod=" + selectMethod + ";";
  }

  private java.sql.Connection getConnection() {
    try {
      Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
      System.out.println(getConnectionUrl());
      con = java.sql.DriverManager.getConnection(getConnectionUrl(), userName,
                                                 password);
      if (con != null) {
        System.out.println("Connection Successful!");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
      System.out.println("Error Trace in getConnection() : " + e.getMessage());
    }
    return con;
  }

  /*
       Display the driver properties, database details
   */

  public void displayDbProperties() {
    java.sql.DatabaseMetaData dm = null;
    java.sql.ResultSet rs = null;
    try {
      con = this.getConnection();
      if (con != null) {
        dm = con.getMetaData();
        System.out.println("Driver Information");
        System.out.println("\tDriver Name: " + dm.getDriverName());
        System.out.println("\tDriver Version: " + dm.getDriverVersion());
        System.out.println("\nDatabase Information ");
        System.out.println("\tDatabase Name: " + dm.getDatabaseProductName());
        System.out.println("\tDatabase Version: " +
                           dm.getDatabaseProductVersion());
        System.out.println("Avalilable Catalogs ");
        rs = dm.getCatalogs();
        while (rs.next()) {
          System.out.println("\tcatalog: " + rs.getString(1));
        }
        rs.close();
        rs = null;
        closeConnection();
      }
      else {
        System.out.println("Error: No active Connection");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    dm = null;
  }

  private void closeConnection() {
    try {
      if (con != null) {
        con.close();
      }
      con = null;
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  public static void main(String[] args) throws Exception {
    String hanzi, pinyin;
    Connection con;
    Statement stat;
    ResultSet rs;
    //Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }
    catch (ClassNotFoundException e) {}
    // Connetion con=DriverManager.getConnection("jdbc:odbc:sjy","","");
    try {
      con = DriverManager.getConnection("jdbc:odbc:sjy", "", "");
      stat = con.createStatement();
      rs = stat.executeQuery("SELECT * from pinyin ");
           while(rs.next())
           {
            System.out.println(rs.getString("hanzi") );
           }



      System.out.println(rs.getString("hanzi") );
      con.close();
    }
    catch (SQLException e) {}

  }


}

⌨️ 快捷键说明

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