JDBC调用代码:导入mysql jar包,junit包
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.junit.Test;
public class Test2 {
@Test
public void test() throws SQLException {
Connection conn = null;
ResultSet rs = null;
CallableStatement cstmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(
"jdbc:mysql://localhost/test",
"root", "root");
cstmt = conn.prepareCall("{call pro_pager(?,?,?,?,?)}");
cstmt.setInt(1, 111111111);
cstmt.setInt(2, 1);
cstmt.setString(3, "select * from student");
cstmt.registerOutParameter(4, 1);
cstmt.registerOutParameter(5, 1);
cstmt.execute();
System.out.println("共" + cstmt.getObject(4) + "条");
System.out.println("共" + cstmt.getObject(5) + "页");
rs = cstmt.getResultSet();
while (rs.next()) {
System.out.print(rs.getString("id") + "----");
System.out.print(rs.getString("name") + "----");
System.out.println(rs.getString("age"));
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
cstmt.close();
conn.close();
}
}
}