当前位置: 技术问答>java相关
如何调用数据库过程?(急,在线)
来源: 互联网 发布时间:2017-03-10
本文导语: Oracle 建立过程Update_projectAdjust(vWoNO in varchar2,adjustDay in number) java程序中建立了Connection con如何调用上面的过程 | CallableStatement cstmt = null; try { Stri...
Oracle 建立过程Update_projectAdjust(vWoNO in varchar2,adjustDay in number)
java程序中建立了Connection con如何调用上面的过程
java程序中建立了Connection con如何调用上面的过程
|
CallableStatement cstmt = null;
try
{
String sql = "{call P_ADD_DOC(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
cstmt = conn.prepareCall(sql);
cstmt.registerOutParameter(7,Types.INTEGER);
cstmt.registerOutParameter(8,Types.INTEGER);
cstmt.registerOutParameter(9,Types.DATE);
cstmt.registerOutParameter(10,Types.INTEGER);
cstmt.registerOutParameter(11,Types.DATE);
cstmt.registerOutParameter(12,Types.INTEGER);
cstmt.registerOutParameter(13,Types.INTEGER);
cstmt.registerOutParameter(14,Types.INTEGER);
cstmt.registerOutParameter(15,Types.INTEGER);
cstmt.registerOutParameter(16,Types.INTEGER);
cstmt.setString(1,title);
cstmt.setInt(2,father.getID());
cstmt.setInt(3,creator.getUserID());
cstmt.setInt(4,CommonDoc.SINGLEDOC);
cstmt.setString(5,firstVersion);
cstmt.setString(6,"00.00.01");
cstmt.execute();
this.ID = cstmt.getInt(7);
this.type = CommonDoc.SINGLEDOC;
this.createTime = cstmt.getDate(9);
this.modifier = cstmt.getInt(10);
this.modifyTime = cstmt.getDate(11);
this.ownerID = cstmt.getInt(12);
this.ownerPermission = cstmt.getInt(13);
this.ownerGroupID = cstmt.getInt(14);
this.groupPermission = cstmt.getInt(15);
this.publicAccess = cstmt.getInt(16);
}
catch(SQLException e)
{
throw new MyException(e,"数据库连接错误!");
}
finally
{
conn.close(cstmt);
}
try
{
String sql = "{call P_ADD_DOC(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
cstmt = conn.prepareCall(sql);
cstmt.registerOutParameter(7,Types.INTEGER);
cstmt.registerOutParameter(8,Types.INTEGER);
cstmt.registerOutParameter(9,Types.DATE);
cstmt.registerOutParameter(10,Types.INTEGER);
cstmt.registerOutParameter(11,Types.DATE);
cstmt.registerOutParameter(12,Types.INTEGER);
cstmt.registerOutParameter(13,Types.INTEGER);
cstmt.registerOutParameter(14,Types.INTEGER);
cstmt.registerOutParameter(15,Types.INTEGER);
cstmt.registerOutParameter(16,Types.INTEGER);
cstmt.setString(1,title);
cstmt.setInt(2,father.getID());
cstmt.setInt(3,creator.getUserID());
cstmt.setInt(4,CommonDoc.SINGLEDOC);
cstmt.setString(5,firstVersion);
cstmt.setString(6,"00.00.01");
cstmt.execute();
this.ID = cstmt.getInt(7);
this.type = CommonDoc.SINGLEDOC;
this.createTime = cstmt.getDate(9);
this.modifier = cstmt.getInt(10);
this.modifyTime = cstmt.getDate(11);
this.ownerID = cstmt.getInt(12);
this.ownerPermission = cstmt.getInt(13);
this.ownerGroupID = cstmt.getInt(14);
this.groupPermission = cstmt.getInt(15);
this.publicAccess = cstmt.getInt(16);
}
catch(SQLException e)
{
throw new MyException(e,"数据库连接错误!");
}
finally
{
conn.close(cstmt);
}
|
callableStatement cstmt = conn.prepareCall("{?=call client_no (?,?)}");
cstmt .registerOutParameter(1,java.sql.Types.Types.VARCHAR);
cstmt .setString(2,"sdfa");
cstmt .setInt(3,2);
cstmt .executeUpdate();
result = cstmt .getString(1);
cstmt .registerOutParameter(1,java.sql.Types.Types.VARCHAR);
cstmt .setString(2,"sdfa");
cstmt .setInt(3,2);
cstmt .executeUpdate();
result = cstmt .getString(1);
|
使用:callableStatement对象
|
http://java.sun.com/products/jdbc/book.html
把JDBC Codes Examples下来
自己看看
把JDBC Codes Examples下来
自己看看