一个关于java调用mysql 存储过程的问题
我有一个java程序:packagedemo1;importjava.sql.CallableStatement;importjava.sql.Connection;im...
我有一个java程序:
package demo1;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;
public class demo17 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String url = "jdbc:mysql://localhost:3306/test03";
String user = "root";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
String sql = "{call test02(?)}";
CallableStatement cst = conn.prepareCall(sql);
cst.registerOutParameter(1, Types.INTEGER);
cst.execute();
int count = cst.getInt(1);
System.out.println(count);
conn.close();
}
}
mysql存储过程是以下这样:
DELIMITER //
CREATE PROCEDURE test02(OUT b INT)
BEGIN
SELECT COUNT(*) FROM test002_book;
END
//
我的test02有5个记录,我在mysql调用以上的存储过程时结果是5,是对的,但在java调用mysql的存储过程时结果是0,我在编写java出现什么问题?请各位高手指教? 展开
package demo1;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Types;
public class demo17 {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String url = "jdbc:mysql://localhost:3306/test03";
String user = "root";
String password = "";
Connection conn = DriverManager.getConnection(url, user, password);
String sql = "{call test02(?)}";
CallableStatement cst = conn.prepareCall(sql);
cst.registerOutParameter(1, Types.INTEGER);
cst.execute();
int count = cst.getInt(1);
System.out.println(count);
conn.close();
}
}
mysql存储过程是以下这样:
DELIMITER //
CREATE PROCEDURE test02(OUT b INT)
BEGIN
SELECT COUNT(*) FROM test002_book;
END
//
我的test02有5个记录,我在mysql调用以上的存储过程时结果是5,是对的,但在java调用mysql的存储过程时结果是0,我在编写java出现什么问题?请各位高手指教? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询