Call a function with one IN parameter with VARCHAR type in Java
Description
The following code shows how to call a function with one IN parameter with VARCHAR type.
Example
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Types;
/*from ww w .jav a 2 s. c o m*/
public class Main {
public static void main(String[] args) throws Exception {
Connection connection = getConnection();
CallableStatement cs = connection.prepareCall("{? = call myfuncin(?)}");
cs.registerOutParameter(1, Types.VARCHAR);
// Set the value for the IN parameter
cs.setString(2, "a string");
// Execute and retrieve the returned value
cs.execute();
String retValue = cs.getString(1);
}
private static Connection getConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
String url = "jdbc:hsqldb:mem:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
}