2010年(59)
分类: 系统运维
2010-03-30 14:41:17
public static void main(String args[]) {
Connection con;
Statement sql; //声明Statement对象
ResultSet rs;
// Connection con1 = null;
// ResultSet rs1 = null;
// PreparedStatement pstmt1 = null;
Transaction t = null;
Session session = HibernateUtils.getNewSession();
t = session.beginTransaction();
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException e) {
System.out.println("11111111111" + e);
}
try {
con = DriverManager.getConnection(
"jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=e:/wfxx.mdb");
sql = con.createStatement();
rs = sql.executeQuery("Select * FROM wfxx");//执行搜索
int i = 0;
while (rs.next()) {
String str1 = rs.getString(1); //获得数据库第一列
String str2 = rs.getString(2);
String str3 = rs.getString(3); //获得数据库第三列
String str4 = rs.getString(4).toString(); //获得数据库第四列
String str5 = rs.getString(5); //获得数据库第五列
String str6 = rs.getString(6); //获得数据库第六列
String str7 = rs.getString(7);
System.out.println("id:" + str1); //输出信息
System.out.println("车辆:" + str2);
String sql2 =
"insert into t_wfxx(id,c_hphm,c_hpzl,c_wfsj,c_wfdz,c_clzt,c_jkzt) values ('" +
str1 + "','" + str2 + "','" + str3 +
"','" + str4 + "','" + str5 + "','" +
str6 + "','" + str7 + "')";
System.out.println(i++ +"sql2:");
//String sql2 = "insert into t_wfxx(id,c_hphm) values ('"+one+"','"+two+"')";
Wfxx wfxx = new Wfxx();
wfxx.setOldid(str1);
wfxx.setHphm(str2);
wfxx.setHpzl(str3);
wfxx.setWfsj(str4);
wfxx.setWfdz(str5);
wfxx.setClzt(str6);
wfxx.setJkzt(str7);
System.out.println("12312312313123");
//类型上报
session.save(wfxx);
}
t.commit();
}
catch (SQLException el) {
System.out.println("11111111111" + el);
t.rollback();
}
finally {
try {
session.close();
// rs1.close();
// pstmt1.close();
// con1.close();
// session.close();
}
catch (Exception e1) {
System.out.println("11111111111" + e1);
}
}
}