MyEclipse 连接MySQL数据库
2010-11-22 00:10
260 查看
这几天都没做题目,因为高级软件工程的大作业很紧张,正好熟悉一下J2EE
连接MySQL数据库分下面几步
//1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//2.获取数据库的连接
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK", "root", "82740591");
//3.获取表达式
Statement stmt=conn.createStatement();
//4.读取数据
ResultSet rs=stmt.executeQuery("select *from user");
//5.显示结果集的数据
while(rs.next()){
System.out.println(rs.getInt(1));
System.out.println(rs.getString("username"));
System.out.println(rs.getString("password"));
System.out.println();
}
//6.释放资源
rs.close();
stmt.close();
conn.close();
连接MySQL数据库分下面几步
//1.注册驱动
Class.forName("com.mysql.jdbc.Driver");
//2.获取数据库的连接
Connection conn= DriverManager.getConnection("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK", "root", "82740591");
//3.获取表达式
Statement stmt=conn.createStatement();
//4.读取数据
ResultSet rs=stmt.executeQuery("select *from user");
//5.显示结果集的数据
while(rs.next()){
System.out.println(rs.getInt(1));
System.out.println(rs.getString("username"));
System.out.println(rs.getString("password"));
System.out.println();
}
//6.释放资源
rs.close();
stmt.close();
conn.close();
相关文章推荐
- Myeclipse连接Mysql数据库
- MyEclipse中用MyEclipse Database Explorer连接mysql数据库时提示错误
- Myeclipse连接mysql数据库心得体会
- 怎么MySQL数据库怎么和MyEclipse连接?
- Hibernate在MyEclipse中的部署,连接MySQL数据库
- myeclipse连接mysql数据库详细步骤
- myeclipse连接mysql数据库详细步骤
- myeclipse中连接mysql数据库示例代码
- Myeclipse与mysql数据库的连接
- myeclipse连接Mysql数据库
- MyEclipse中连接mysql数据库提示error while performing database login with the testMySQL driver check your url
- myeclipse通过jdbc 连接mysql数据库
- Myeclipse连接mysql数据库(给力的写)全程心得)
- Myeclipse连接Mysql数据库时报错:Error while performing database login with the pro driver:unable
- MyEclipse使用Java 通过JDBC连接MySQL数据库的基本测试
- android开发 MyEclipse下测试连接MySQL数据库
- MyEclipse连接MySql数据库管理系统
- myeclipse自带客户端连接mysql数据库
- MyEclipse与Mysql数据库的连接
- MyEclipse连接MySQL数据库报错解决办法