怎样用JDBC访问SQL SERVER2005数据库的存储过程
怎样用JDBC访问SQL SERVER2005数据库的存储过程,并提供相应输入、输出参数
想要一示例代码 谢谢
[解决办法]
private Connection connection = null;
public String CheckLogin(String username, String pwd) {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
connection = DriverManager.getConnection(
"jdbc:sqlserver://127.0.0.1;DatabaseName=StudentGrade",
"sa", "123456");
CallableStatement call = connection
.prepareCall("{call proc_DemoLogin(?,?)}"); //proc_DemoLogin 你写好的存储过程名字
call.setString(1, username); //参数设置
call.setString(2, pwd);
ResultSet resultSet = call.executeQuery();
if (resultSet.next()) {
return resultSet.getString(1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return null;
}