我有一个过程,它接受两个String参数并从数据库Oracle 10g返回Integer值。
当尝试打印出结果时,我得到了无效的列索引。
代码是
try {
Dbconnection NewConnect = new Dbconnection();
Connection con = NewConnect.MakeConnect();
CallableStatement stmt1 = ((Connection) con).prepareCall("{ call login (?, ?, ?)}");
stmt1.registerOutParameter(1, Types.INTEGER);
stmt1.setString(2, "ahmed");
stmt1.setString(3, "ahmed");
ResultSet rslt = stmt1.executeQuery();
if (rslt.next())
{
System.out.println( rslt.getInt(1));
}
程序登录
create or replace
PROCEDURE login
(p_username teacher.username%TYPE,
p_password teacher.password%TYPE)
IS
v_teacher_id teacher.teacher_id%TYPE;
v_username teacher.username%TYPE ;
v_password teacher.password%TYPE ;
BEGIN
SELECT teacher_id, username , password
INTO v_teacher_id , v_username , v_password
FROM teacher
where username = p_username and password =p_password ;
DBMS_OUTPUT.PUT_LINE (v_teacher_id);
end login ;
答案 0 :(得分:0)
很好尝试但这里存在一些错误.... 这样做......你的输出你会100%肯定地回复。
CREATE OR REPLACE PROCEDURE login
( v_teacher_id OUT teacher.teacher_id%TYPE,
p_username IN teacher.username%TYPE,
p_password IN teacher.password%TYPE)
IS ..... (blah blah blah)
告诉我onething,如果你没有在程序开始时提供任何输出参数,你如何期望Java代码中的输出?
现在试试,你将从java Code
获得你的输出 rslt.getInt(1)
所有最好的:))Surajit