zoukankan      html  css  js  c++  java
  • 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;
    	}
    

      

  • 相关阅读:
    markdown with vim
    递归
    类 sizeof
    cppcheck工具
    c++ explicit的含义和用法
    pca主成分分析
    string的使用
    linux的shell进化简史
    adb shell 无法启动 (insufficient permissions for device)
    c++ 四种转换的意思
  • 原文地址:https://www.cnblogs.com/justphp/p/3619639.html
Copyright © 2011-2022 走看看