Java使用使用JDBC连接连接Oracle_MSSQL实例代码实例代码
主要介绍了Java使用JDBC连接Oracle_MSSQL实例代码,需要的朋友可以参考下
一、Statement
复制代码 代码如下:
import java.sql.*;
public class TestJDBC {
public static void main(String[] args) {
Connection oracle_conn = null;
Statement oracle_stmt = null;
ResultSet oracle_rs = null;
Connection mssql_conn = null;
Statement mssql_stmt = null;
ResultSet mssql_rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
oracle_conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.215:1521:orcl", "username", "password");
oracle_stmt = oracle_conn.createStatement();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
mssql_conn = DriverManager.getConnection("jdbc:sqlserver://192.168.0.213:1433;DatabaseName=VIS", "username",
"password");
mssql_stmt = mssql_conn.createStatement();
mssql_rs = mssql_stmt.executeQuery("select * from VideoBaseInfo");
while(mssql_rs.next()) {
System.out.println("正在插入VideoId:" + mssql_rs.getInt("VideoId") + "的记录...");
oracle_stmt.executeUpdate("insert into VIDEO_BASEINFO values("
+ mssql_rs.getInt("VideoId") + ",'"
+ mssql_rs.getString("VideoName") + "','"
+ mssql_rs.getString("VideoVersion") + "',"
+ mssql_rs.getInt("VideoMp4Items") + ","
+ mssql_rs.getInt("VideoRmvbItems") + ",'"
+ mssql_rs.getString("VideoAliasName") + "','"
+ mssql_rs.getString("VideoAge") + "'"
+ ")");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if(oracle_rs != null) {
oracle_rs.close();
oracle_rs = null;
}
if(oracle_stmt != null) {
oracle_stmt.close();
oracle_stmt = null;
}
if(oracle_conn != null) {
oracle_conn.close();
oracle_conn = null;
}
评论0
最新资源