@Test
public void jdbcDriver() throws SQLException{
//需要mysql-connection-java.jar
List
@Test
public void jdbcDriver() throws SQLException{
//需要mysql-connection-java.jar
List<String[]> list=new ArrayList<String[]>();
Connection con=null;
PreparedStatement ps=null;
ResultSet rs=null;
String sql="select * from stu";
try {
Class.forName("com.mysql.jdbc.Driver");
//注意这个地方是mysql数据库
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//三个变量分别是jdbc:mysql://localhost:3306/test root root
String url="jdbc:mysql://localhost:3306/test";
String user="root";
String pwd="";
con=DriverManager.getConnection(url,user,pwd);
ps=con.prepareStatement(sql);
rs=ps.executeQuery();
while(rs.next()){
String[] users=new String[6];
users[0]=rs.getString(1);
//注意rs只能从1开始
users[1]=rs.getString(2);
list.add(users);
}
rs.close();
ps.close();
con.close();
}