import java.sql.*;
public class JDBCTest {
public static void main(String[] args){
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://127.0.0.1:3306/emenu";
String user = "root";
String password = "root";
try {
// 加载驱动程序
Class.forName(driver);
// 连接数据库
Connection conn = DriverManager.getConnection(url, user, password);
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from student";
// 结果集
ResultSet rs = statement.executeQuery(sql);
Student s = null;List<Student> sList = new ArrayList<Student>;while(rs.next()) {
s = new Student();s.setId(rs.getLong(1));s.setName(rs.getString(2));sList.add(s);
}
}
rs.close();
conn.close();
} catch(ClassNotFoundException e) {
} catch(SQLException e) {
} catch(Exception e) {}