日期:2014-05-16 浏览次数:20409 次
insert into T1 (ID, VALUE) select ID, VALUE from T2
import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import oracle.jdbc.driver.OracleDriver; public class TestOracleUtil { public static void main(String[] args) throws SQLException { String sql = "insert into T1 (ID, VALUE) select ID, VALUE from T2"; update(getConnection(), sql); } public static Connection getConnection() { new OracleDriver(); String serverName = "192.168.1.3"; String portNumber = "1521"; String sid = "ORCL"; String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid; String username = "test"; String password = "test"; try { Connection conn = DriverManager.getConnection(url, username, password); return conn; } catch (SQLException e) { e.printStackTrace(); return null; } } static void update(Connection conn, String sql) throws SQLException{ Statement smt = conn.createStatement(); smt.executeUpdate(sql); } }