---
title: "jdbc建立实例"
author: "stopit"
date: "2012-06-27T22:51:41Z"
tags: []
categories: ["数据库"]
slug: "jdbc"
draft: false
lastmod: "2012-06-27T22:51:41Z"
id: 1569434
url: "https://stopit.iteye.com/blog/1569434"
---

```
Class.forName("com.mysql.jdbc.Driver");// 启动driver
		Connection conn = DriverManager
				.getConnection("jdbc:mysql://localhost:3306/mysql?user=root&password=123456");// 得到数据库连接
		Statement sql = conn.createStatement();// 创建sql实例
		ResultSet rs = sql.executeQuery("select * from test.ex");// 执行语句
```

1.启动driver

2.通过driver管理器创建数据库连接，其中：

jdbc:mysql://localhost: 3306/mysql?user=root&password=\*\*\*\*\*\*是数据库URL地址，前面都是固定的，3306是端口号，安装mysql的时候有提示，mysql是数据库的名字，user是用户名，password后面填写密码。

3.通过连接创建实例；

4.使用实例执行sql语句并对数据库进行操作