Call a procedure with one IN parameter in Java
Description
The following code shows how to call a procedure with one IN parameter.
Example
//w w w . j av a 2 s . co m
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = getConnection();
// Call a procedure with no parameters
CallableStatement cs = connection.prepareCall("{call myprocin(?)}");
// Set the value for the IN parameter
cs.setString(1, "a string");
cs.execute();
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}