package cn.zkjc.sp.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
static final String DRIVER="com.mysql.jdbc.Driver";
static final String URL="jdbc:mysql://localhost:3306/test";
static final String USERNAME="root";
static final String PWD="root";
public static Connection getConnection() throws ClassNotFoundException, SQLException{
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USERNAME, PWD);
}
/**
* @param args
* @throws SQLException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection con = getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("{call getUserCount()}");
// ResultSet rs = st.executeQuery("{call getAllUser()}");
while(rs.next()){
System.out.println(rs.getInt("count(*)"));
}
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
static final String DRIVER="com.mysql.jdbc.Driver";
static final String URL="jdbc:mysql://localhost:3306/test";
static final String USERNAME="root";
static final String PWD="root";
public static Connection getConnection() throws ClassNotFoundException, SQLException{
Class.forName(DRIVER);
return DriverManager.getConnection(URL, USERNAME, PWD);
}
/**
* @param args
* @throws SQLException
* @throws ClassNotFoundException
*/
public static void main(String[] args) throws ClassNotFoundException, SQLException {
Connection con = getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("{call getUserCount()}");
// ResultSet rs = st.executeQuery("{call getAllUser()}");
while(rs.next()){
System.out.println(rs.getInt("count(*)"));
}
}
}
上图为转载内容