简体   繁体   中英

Calling stored procedure in jdbc

I am developing android application. And i am using sql sever 2008 database to store and retrieve the data. Now i am calling the stored procedure in jbdc. Here is the code . Now it gives me Exception which says Invalid Column Index at 3. I am using the same code in other place which works fine. Bt don't know why nt working here. Give proper advice if you have any idea. Thank You.

I just found out that when the String dat = rs.getString(3); is executing it shows the above exception. Let me tell you that in stored procedures it was datetime. But it executes well. Any suggestions do help me.

Here is the stored Procedure

From looking at your java code, it would appear that your parameters are either OUT or INOUT params. If that is the case, you probably need to register them as such, so you can get data from them.

eg

cst.setInt(1,userId);
cst.setLong(2,taskId);
cst.setString(3, date);

cst.registerOutParameter(1, Types.NUMERIC);
cst.registerOutParameter(2, Types.NUMERIC);
cst.registerOutParameter(3, Types.VARCHAR);

rs = cst.executeQuery();

Hopefully, that should fix your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM