标签:callable oid cep ber out public not drive exe
/**
* 连接oracle
*/
@Test
public void connectTest() {
String driver="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:@192.168.43.208:1521:orcl";
String username="scott";
String password="tiger";
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
String sql = "select * from emp";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next()) {
System.out.println(resultSet.getObject(1));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 访问存储过程
*/
@Test
public void connectTest1() {
String driver="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:@192.168.43.208:1521:orcl";
String username="scott";
String password="tiger";
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
CallableStatement callableStatement = connection.prepareCall("{call getYearSal(?,?)}");
callableStatement.setInt(1,7788);
callableStatement.registerOutParameter(2, OracleTypes.NUMBER);
callableStatement.execute();
Object object = callableStatement.getObject(2);
System.out.println(object);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 访问存储函数
*/
@Test
public void connectTest2() {
String driver="oracle.jdbc.OracleDriver";
String url="jdbc:oracle:thin:@192.168.43.208:1521:orcl";
String username="scott";
String password="tiger";
try {
Class.forName(driver);
Connection connection = DriverManager.getConnection(url, username, password);
CallableStatement callableStatement = connection.prepareCall("{? = call getSals(?)}");
callableStatement.setInt(2,7788);
callableStatement.registerOutParameter(1, OracleTypes.NUMBER);
callableStatement.execute();
Object object = callableStatement.getObject(1);
System.out.println(object);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
标签:callable oid cep ber out public not drive exe
原文地址:https://www.cnblogs.com/zhz-8919/p/11124819.html