我现在要把server数据库中的一个表的id字段数据。。导到oracle中一个表的id字段中
我现在使用2个connection交互做。。不过出了些小问题。。
public class A00AirLawBo{ public void importData(Connection sqlCon, Connection oraCon)
throws Exception {
Statement sqlSta = sqlCon.createStatement();
ResultSet sqlRs = sqlSta.executeQuery("select * from AIRLAW");
int id = sqlRs.getInt("id"); 先查出ID 20行(这里报错)
PreparedStatement oraSta = oraCon.prepareStatement("insert into AIRLAW(id) values(?)");
while(sqlRs.next()){
oraSta.setInt(1, id); 插进oracle中
oraSta.execute();
}
sqlRs.close();
oraSta.close();
sqlSta.close();
}
}
测试方法
public static void main(String args[]){
Connection oraCon = null;
Connection sqlCon = null;
try {
oraCon = new OracleConnection().getConnection();
sqlCon = new SQLServerConection().getConnection();
sqlCon.setAutoCommit(false);
A00AirLawBo a = new A00AirLawBo();
a.importData(sqlCon, oraCon); //调用上面的方法15行(这里报错)
sqlCon.commit();
} catch (Exception e) {
try {
sqlCon.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}报错
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at com.ninemax.bo.A00AirLawBo.importData(A00AirLawBo.java:15)
at com.ninemax.bo.TableCreator.main(TableCreator.java:20)
}
我现在使用2个connection交互做。。不过出了些小问题。。
public class A00AirLawBo{ public void importData(Connection sqlCon, Connection oraCon)
throws Exception {
Statement sqlSta = sqlCon.createStatement();
ResultSet sqlRs = sqlSta.executeQuery("select * from AIRLAW");
int id = sqlRs.getInt("id"); 先查出ID 20行(这里报错)
PreparedStatement oraSta = oraCon.prepareStatement("insert into AIRLAW(id) values(?)");
while(sqlRs.next()){
oraSta.setInt(1, id); 插进oracle中
oraSta.execute();
}
sqlRs.close();
oraSta.close();
sqlSta.close();
}
}
测试方法
public static void main(String args[]){
Connection oraCon = null;
Connection sqlCon = null;
try {
oraCon = new OracleConnection().getConnection();
sqlCon = new SQLServerConection().getConnection();
sqlCon.setAutoCommit(false);
A00AirLawBo a = new A00AirLawBo();
a.importData(sqlCon, oraCon); //调用上面的方法15行(这里报错)
sqlCon.commit();
} catch (Exception e) {
try {
sqlCon.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
}报错
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.validateCursorPosition(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)
at com.ninemax.bo.A00AirLawBo.importData(A00AirLawBo.java:15)
at com.ninemax.bo.TableCreator.main(TableCreator.java:20)
}
解决方案 »
- 这。。好诡异啊
- 求正则匹配CPU,MAC地址?
- 服务器端如何循环取到客户端脚本动态生成的html元素的值
- ajax返回数据的xml编码是乱码
- Struts+jdbc 实现的
- 十万火急:请问JBoss4如何设置虚拟目录?
- 动态搜索一定要处理跟显示分开两个界面吗
- 难题:若Array[][]类型中存放file、image等对象,如何提交和接收?(不能单独发送file、image)
- 初学Struts请教:从多的标签有必要深入学吗,你们都用吗?!使用标签在速度上跟原始的代码潜入比如何?!
- 刷新某条记录的新方法!!
- hibernate中createSqlQuery()的用法???(高手请进)
- 大家给个做个图片管理系统的思路
放到while里面
PreparedStatement oraSta = oraCon.prepareStatement("insert into AIRLAW(id) values(?)");
while(sqlRs.next()){
int id = sqlRs.getInt("id"); // 放这里看看
oraSta.setInt(1, id); 插进oracle中
oraSta.execute();
}