<< 理解Java的synchronized关键字 | 首页 | IP地址快速切换bat >>

使用JDBC-ODBC访问Access数据库的Memo备注类型字段

两种使用Java访问Access数据库Memo备注字段的方法

  //使用纯Java的jackcess驱动程序访问MS Access MDB数据库
  try {
   Table lawTable = Database.open(new File("E:\\falv\\falv.mdb"))
     .getTable("xz2");
   Iterator iter = lawTable.iterator();
   int i = 0;
   while (iter.hasNext()) {
    if (i > 25) {
     break;
    }
    Map m = (Map) iter.next();

    System.out.println(m.get("xh"));
    System.out.println(m.get("content"));

    i++;
   }

  } catch (IOException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }

  //使用JDBC-ODBC访问Access数据库的Memo备注类型字段
  Connection conn=null;
  Statement stmt=null;
  ResultSet rs=null;
  String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E:\\falv\\falv.mdb";
  try {
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   conn= DriverManager.getConnection(url, "Administrator",
     "sjaJObQGsEWk6OZXLOl");
   stmt = conn.createStatement();
   rs = stmt.executeQuery("select  * from xz2 where xh=25");
   // ResultSet rs = stmt.executeQuery("select count(*),type from xz2
   // group by type");
   while (rs.next()) {
    System.out.println(rs.getString("type"));

    Reader is = rs.getCharacterStream("content");
    BufferedReader br = new BufferedReader(is);
    StringBuffer sb = new StringBuffer();
    String s;
    try {
     s = br.readLine();
     while (s != null) {
      sb.append(s);
      s = br.readLine();
     }
     System.out.println(sb.toString());
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }


   }
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally{
   try {
    rs.close();
    stmt.close();
    conn.close();
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

  }

标签 : , ,



发表评论 发送引用通报