JDBC编程
public static ArrayList newjdbc(String url , String sql) { Connection conn=null; Statement st=null; ResultSet rt=null; ArrayList data = new ArrayList(); try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/vapor?user=root&password=root"); st = conn.createStatement(); rt = st.executeQuery("SELECT * FROM vp_user"); int index=0; while(rt.next()) { data.add(rt.getString("uname")); } } catch (ClassNotFoundException e) { // TODO Auto-generated catch block System.out.println(e.toString()); } catch (SQLException e) { // TODO Auto-generated catch block System.out.println(e.toString()); } finally { try { if(rt!=null){ rt.close(); rt=null; } if(st!=null){ st.close(); st=null; } if(conn!=null){ conn.close(); conn=null; } } catch (SQLException e) { // TODO Auto-generated catch block System.out.println(e.toString()); } } return data; }