jdbc 顯示所有庫

		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306","root","root");

			Statement stmt=con.createStatement();
			ResultSet rs=stmt.executeQuery("show databases;");
			   while(rs.next())
			   {
			    System.out.println(rs.getString(1));  
			   }
			    rs.close();
			    stmt.close();
			    con.close();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章