【文件属性】:
文件名称:jdbc-odbc的基本操作
文件大小:629KB
文件格式:7Z
更新时间:2015-01-16 08:05:06
jdbc-odbc的基本操作,完整流程
/**
* @param dbPath
* 数据库存储路径
* @param tel
* 所查询的手机号码
* @return
* 号码所属地
*/
public String getLocationByTel(String dbPath,String tel){
String result = null;
Connection cn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
//连接的是jdbc-odbc桥
String dbUrl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+dbPath;
cn = DriverManager.getConnection(dbUrl);
pstmt = cn.prepareStatement("select PCity from shouji where ?=PhoneNo");
pstmt.setString(1, tel.substring(0, 7));
rs = pstmt.executeQuery();
if (rs.next()) {
result=new String(rs.getBytes("PCity"),"gbk");//访问数据库中文乱码问题
//result = rs.getString(1);
} else {
result = tel + "属于未知地区";
}
} catch (Exception e) {
// throw new MyException(e);
e.printStackTrace();
} finally {
// 下面省略关闭的详细代码,只简单示意一下
try {
if (rs != null) {
rs.close();
}
if (pstmt != null) {
pstmt.close();
}
if (cn != null) {
cn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return result;
}
【文件预览】:
jdbc-odbc桥
----mobileAddress.mdb(28.67MB)
----TelSeekLocation.java(2KB)