由于刚学习这个所以不知道错在哪,请各位帮我看看,哪有问题
package pack1;
import java.sql.*;
public class Process {
public static void main(String[] args) {
Connection conn = null;
ResultSet rs = null;
CallableStatement cstmt = null;
String sDBDriver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
String url =
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Mymessage ";
String sql = "{call getMessage} ";
try {
Class.forName(sDBDriver);
conn = DriverManager.getConnection(url, "sa ", "123 ");
cstmt = conn.prepareCall(sql);
rs = cstmt.executeQuery();
while (rs.next()) {
System.out.println( "------------------------------- ");
System.out.println( " " + rs.getString(1));
System.out.println( " " + rs.getString(2));
}
}
catch (Exception e) {
System.err.println( "executeProc: " + e.getMessage());
}
finally {
try {
cstmt.close();
}
catch (SQLException ex) {
}
try {
conn.close();
}
catch (SQLException ex1) {
}
}
}
}
------解决方案--------------------
String sql = "{call getMessage} ";---> > String sql = "{call getMessage()} ";
出问题最后把错误信息弄出来,要不一大段代码看了就晕了
------解决方案--------------------
.....
应该是 "{call getMessage(?,?)} ";存储过程几个参数几个问号