Test.java
上传用户:mkymky1985
上传日期:2014-06-23
资源大小:754k
文件大小:1k
- package wsxk;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.sql.DriverManager;
- public class Test {
-
- public static Connection init(){
- Connection conn = null;
- String url = "jdbc:odbc:xuanke";
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- conn = DriverManager.getConnection(url);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return conn;
-
- }
- public ArrayList select(){
- ArrayList list = new ArrayList();
- Connection conn = this.init();
- try {
- Statement stat = conn.createStatement();
- ResultSet rs = stat.executeQuery("select * from admin");
- while(rs.next()){
- list.add(rs.getString(1));
- list.add(rs.getString(2));
-
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- return list;
- //在线课题选课系统
- }
- public static void main(String args[]){
- Test t = new Test();
- ArrayList list = t.select();
- for(Iterator it =list.iterator();it.hasNext();){
- System.out.println(it.next());
-
- }
-
- }
- }