简体   繁体   中英

How to pass IN parameter to a mysql stored procedure

Hello Im really new to Java and mysql. I want to know how to pass an IN parameter to my mysql stored procedure by using a callable statement in JAVA. Here is my code below I cant get it to work!

Connection conn = DriverManager.getConnection
("jdbc:mysql://"+host+":3306/"+database, user, pass);

conn.setAutoCommit(false);


CallableStatement cs1 = conn.prepareCall("Call get_school_address_details()");
cs1.setInt(1);

ResultSet res = cs1.executeQuery();

System.out.println("Result of SP");

while (res.next())
{
    System.out.println (res.getString(1) + " " + res.getString(2) + " " + res.getString(3));

}

It doesnt seem to like the way i have tried to passs the parameter using cs1.setInt(1)

Suggestions please! All i want to pass it is the value 1 which is an int

通过传递参数名称然后传递我想传递的值(在这种情况下为数字1)来解决该问题:

cs1.setInt("sch_code",1);

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