JDBC中Statement,PreparedStatement,CallableStatement三个方法的实例 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-18
hedule = Ex1rs.getString(3);
System.out.println(ClassName,ClassLocation,ClassSchedule);
}
}
//使用CallableStatement显示成绩
//预先定义好的存储过程的调用形式为:studentGrade = getStudentGrade(StudentID, ClassID)
public void DisplayGrade(String StudentID, String ClassID) throws SQLException
{
int Grade;
//Initialize and load the JDBC-ODBC dirver.
Class.forName("jdbc.odbc.JdbcOdbcDriver");
//Make the connection object;
Connection Con = DriverManager.getConnection("jdbc:odbc:studentDB";uid="admin";pw="sa");
//Create a Callable Statement object;
CallableStatement CStmt = Con.prepareCall({? = call getStudentGrade[?,?]});
//Now tie the placeholders with actual parameters.
//Register the return value from the stored procedure
//as an integer type so that the driver knows how to handle it.
//Note the type is defined in the java.sql.Types.
CStmt.registerOutParameter(1,java.sql.Types.INTEGER);
//Set the In parameters (which are inherited from the PreparedStatement class)
CStmt.setString(1,StudentID);
CStmt.setString(2,ClassID);
//Now we are ready to call the stored procedure
int RetVal = CStmt.excuteUpdate();
//Get the OUT Parameter from the registered parameter
//Note that we get the result from the CallableStatement object
Grade = CStmt.getInt(1);
//And display the results on the console;
System.out.println("The Grade is:" + Grade);
} |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于JDBC中Statement,PreparedStatement,CallableStatement三个方法的实例 - 编程入门网的所有评论