java调用SQL Server Express 存储过程
package cn;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Types;
public class Testjava {
public static void main(String[] args) {
String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver ";
String url = "jdbc:sqlserver://localhost:1433;database=PetShop ";
String username = "sa ";
String password = "1234 ";
showDepartments(driver, url, username, password);
}
private static void showDepartments(String driver, String url,
String username, String password) {
try {
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
CallableStatement statement = conn.prepareCall( "{call GetProductsInCategory(?,?,?,?,?)} ");
statement.setInt( "CategoryID ", 1);
statement.setInt( "DescriptionLength ", 20);
statement.setInt( "PageNumber ", 1);
statement.setInt( "ProductsPerPage ", 8);
statement.registerOutParameter( "HowManyProducts ", Types.INTEGER);
boolean success = statement.execute();
System.out.println(success);
ResultSet rs = null;
if (success) {
int howManyProducts = statement.getInt(5);
System.out.print(howManyProducts);
rs = statement.getResultSet();
while (rs.next()) {
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
}
}
statement.close();
conn.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
}
}
为什么这句boolean success = statement.execute();总是为false ?
存储过程调试过是正确的。
哪位高人解答下?
------解决方案--------------------eclipse3.3出来了?-____-bb汗
你把boolean success = statement.execute();这句改成:
boolean success;
success = statement.execute();再看看是不是解决了^O^
------解决方案--------------------知道了,谢谢!!!!!