1. CallableStatement 是在什么场合下使用的
CallableStatement cstmt = con.prepareCall(
"{call getTestData(?, ?)}");
和一般的
conn= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:haha","he","123");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
s=stmt.executeQuery(sql);(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);有什么区别?谁更好?能不能举个例子?2. "{call getTestData(?, ?)}");里面的getTestData是一个过程名,我想问问这个过程名是什么?具体在程序里面会是什么?我对这个过程名没有一点概念,弄得我很糊涂举个例子可以吗?3. 大家可以都来讨论一下CallableStatement 的方法与同样功能的其他方法的比较,这样可以让我立体的理解它,当然例子多多最好,谢谢各位。
CallableStatement cstmt = con.prepareCall(
"{call getTestData(?, ?)}");
和一般的
conn= DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:haha","he","123");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
s=stmt.executeQuery(sql);(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);有什么区别?谁更好?能不能举个例子?2. "{call getTestData(?, ?)}");里面的getTestData是一个过程名,我想问问这个过程名是什么?具体在程序里面会是什么?我对这个过程名没有一点概念,弄得我很糊涂举个例子可以吗?3. 大家可以都来讨论一下CallableStatement 的方法与同样功能的其他方法的比较,这样可以让我立体的理解它,当然例子多多最好,谢谢各位。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;public class Test_p { public static void main(String[] args) {
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@192.168.0.91:1521:数据库名";
String user="数据库用户名";
String password="密码";
Connection conn=DriverManager.getConnection(url,user,password);
String name_=null ;
String password_=null;
String id="002";
String sql="call procedure(?,?,?)";
CallableStatement cs=conn.prepareCall(sql);
cs.setString(1,id) ;
cs.setString(2,name_) ;
cs.setString(3,password_) ;
cs.registerOutParameter(2,Types.LONGVARCHAR) ;
cs.registerOutParameter(3,Types.LONGVARCHAR) ;
cs.execute();
name_=cs.getString(2);
password_=cs.getString(3);
System.out.println(id+" "+name_+" "+password_);
cs.close();
conn.close();
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}}
="call procedure(?,?,?)";
这里的procedure是自己随便定义的一个名字,还是调用什么地方的什么名字?哦,这个就应该是存储过程名?可是这个存储过程是什么东西啊,就是这个我不理解,它的格式是什么?作用是什么?能举个它的例子吗?
IS
name_ lj_temp.name%type;
BEGIN
select name into name_ from lj_temp where id=12345;
dbms_output.put_line('323232 :'||name_||'dwadwads');
exception
when others then
dbms_output.put_line('!!!!!!!!!!! ');
END;
随便找的存储过程给你发一个吧