第一:调用函数的例子:
package daniel.test;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;
public class ConnectionPro {
/**建立数据库的连接
* @param args
*/
public static Connection getConnection(){
Connection con=null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String url="jdbc:oracle:thin:@PC-200911181406:1521:dgy";
String user="dwj";
String pwd="dwj";
try {
con = DriverManager.getConnection(url,user,pwd);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
public static void main(String[] args) throws SQLException {
Connection con=ConnectionPro.getConnection();
CallableStatement sc=con.prepareCall("{?=call get_temp(?,?)}");
sc.registerOutParameter(1,Types.VARCHAR);
sc.setString(2,"12");
sc.registerOutParameter(3, Types.VARCHAR);
sc.execute();
System.out.println(sc.getString(1));
System.out.println(sc.getString(3));
}
}
output:
Alex
Alex
此章节的笔记由同事daven整理,细节点击此处查看!