import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
public class Main {
public static void main(String[] argv) throws Exception {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://MYSERVER;databaseName=MYDATABASE",
"USERID", "PASSWORD");
CallableStatement proc_stmt = con.prepareCall("{ call generateID(?) }");
proc_stmt.setString(1, "employee");
ResultSet rs = proc_stmt.executeQuery();
if (rs.next()) {
int employeeId = rs.getInt(1);
System.out.println("Generated employeeId: " + employeeId);
} else {
System.out.println("Stored procedure couldn't generate new Id");
}
}
}
|