本帖最后由 张胜格 于 2012-12-31 10:05 编辑
下面的代码可以参考一下:
public class Test1{
public static void main(String[] args) throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:folkmusic");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from main");//获得数据库操作的结果
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn1 = DriverManager.getConnection("jdbc:oracle:thin.@127.0.0.1:1521:java","java1","test123");
//conn1.setAutoCommit(false);
while(rs.next()){//根据结果完成相应的操作
String content = rs.getString("content");
BufferedWriter bw = new BufferedWriter(new FileWriter("tmpfile.txt"));
bw.write(content);
bw.flush();
bw.close();
PreparedStatement stmt1 = conn1.prepareStatement("insert into main (content) values (?)");
InputStream is = new FileInputStream(new File("tmpfile.txt");
stmt1.setBinaryStream(1,is,is.available());
stmt1.executeUpdate();
}
//conn1.commit();
rs.close();
//stmt1.close();
}
};
|