在Java 中执行下面SQL语句没有响应,DEBUG 无法跟踪代码,但此语句在SQL DEVELOPER 执行没问题,在Java代码中执行其他 SQL 语句基本也没问题。
class="sql" name="code">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);
}
}