//第一种
private static void ddd(){
try {
//Properties p = new Properties();
//p.put("charSet", "UTF-8");
Class.forName("com.hxtt.sql.access.AccessDriver");
Connection c = DriverManager.getConnection("jdbc:Access:///d:/table.mdb");
ResultSet r = c.createStatement().executeQuery("SELECT * FROM table;");
while(r.next()){
byte[] bts=null;
String other = null;
bts = r.getBytes(3); //读取other字段
if(bts != null) {
other = new String(bts,"gbk");
}
System.out.print(other);
}
} catch (Exception e) {
e.printStackTrace();
}
}
//第二种
private static void mdb(){
Table db;
try {
DatabaseBuilder dbb = new DatabaseBuilder();
Charset cs = Charset.defaultCharset();
dbb.setCharset(cs);
db = dbb.open(new File("d://table.mdb")).getTable("table");
int count = db.getRowCount();
for(Row row : db) {
String bt = new String(row.getString("maintitle").getBytes("GBK"),"UTF-8");
System.out.println("--照片名称--" + row.get("recid")+"----biaot="+bt);
}
} catch (IOException e) {
e.printStackTrace();
}
}
//第三种
private static void ddd1(){
try{
Connection conn = null;
Statement st = null;
ResultSet rs = null;
String dbName = "d://table.mdb";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dbur1 = "jdbc:odbc:KY";// 此为ODBC连接方式
//String url ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+dbName;//此为NO-DSN方式
//System.out.println("mdb文件路径:"+dbName);
Properties prop = new Properties(); //只要添加这几句话就可以
prop.put("charSet","GBK");
prop.put("user", "");
prop.put("password", "");
conn=DriverManager.getConnection(dbur1,prop);
st=conn.createStatement();
rs=st.executeQuery("select * from archive_description_jh");
while(rs.next()){
//String str=rs.getString(3);
System.out.println(new String(rs.getString(3).getBytes(),"UTF-8")) ;
//System.out.println(str);
}
//conn.setCatalog(dbName);
/* ResultSet tables = conn.getMetaData()
.getTables(dbName,null,null,new String[]{"TABLE"});*/
/* while(tables.next()){
String str = tables.getString(3);
}*/
} catch(Exception e)
{
System.out.print(e.getMessage());
}
}