main.ja

来自「java操作xml文件的各种代码」· JA 代码 · 共 54 行

JA
54
字号
import AddressBookInfo;
import JDAO;
import java.sql.*;
import java.util.Vector;

public class Main {
  private Connection con;
  private Vector vPerson;

  private void initDB(){
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = DriverManager.getConnection("jdbc:odbc:address");
    } catch( Exception e ){
      e.printStackTrace(System.out);
    }
  }

  private void getAddressBookInfo(){
    try{
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery(
        "select 姓名,"+
        "       昵称,"+
        "       电子邮件帐号,"+
        "       上次开会日期,"+
        "       备注 "+
        "from 名片簿;");

      JDAO jDAO = new JDAO("AddressBookInfo.xml");
      vPerson = jDAO.parseResultSet(rs);

      rs.close();
      stmt.close();
    } catch( Exception e ){
      e.printStackTrace(System.out);
    }// end of catch
  }

  public static final void main(String[] args){
    Main mainApp = new Main();
    mainApp.initDB();
    mainApp.getAddressBookInfo();

    for(int i=0; i<mainApp.vPerson.size(); i++){
      AddressBookInfo abi = (AddressBookInfo)mainApp.vPerson.get(i);
      System.out.println("姓名= " + abi.getName());
      System.out.println("昵称= " + abi.getNickName());
      System.out.println("电子邮件= " + abi.getEmail());
      System.out.println("上次开会日期= " + abi.getMeetDate());
      System.out.println("备注= " + abi.getMemo());
    }
  }
}

⌨️ 快捷键说明

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