---
title: "jdbc  显示所有库"
author: "lanfei"
date: "2014-11-28T11:04:14Z"
tags: []
categories: ["编程语言"]
slug: "jdbc"
draft: false
lastmod: "2014-11-28T11:04:58Z"
id: 2161710
url: "https://lanfei.iteye.com/blog/2161710"
---

```
		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();
		}
```