Java Reference
In-Depth Information
Listing 13-10 provides an example of using the simple stored procedure of Listing 13-9 . Notice the call
to the registerOutParameter() method prior to calling the CallableStatement's getString
method to retrieve the output parameter.
Listing 13-10: Getting an output parameter from a stored procedure
package JavaDatabaseBible.ch13;
import java.sql.*;
import javax.sql.*;
public class CheckPassword{
private static String dbUserName = "sa";
private static String dbPassword = "dba";
public static void main(String args[]){
int id = -1;
String password = null;
String username = "";
if(args.length>0)username = args[0];
try {
Class.forName("com.inet.pool.PoolDriver");
com.inet.tds.TdsDataSource tds = new com.inet.tds.TdsDataSource();
tds.setServerName( "JUPITER" );
tds.setDatabaseName( "MEMBERS" );
tds.setUser( dbUserName );
tds.setPassword( dbPassword );
DataSource ds = tds;
Connection con = ds.getConnection(dbUserName,dbPassword);
CallableStatement cs = con.prepareCall("{call
CHECK_USER_NAME(?,?,?)}");
cs.setString(1,"garfield");
cs.setString(2,"lasagna");
cs.registerOutParameter(3, java.sql.Types.VARCHAR);
cs.executeUpdate();
System.out.println(cs.getString(3));
}
catch(ClassNotFoundException e){
e.printStackTrace();
}
catch(SQLException e){
e.printStackTrace();
Search WWH ::




Custom Search