最近看了几篇关于myeclipse6.0 连接和管理DB 的帖子,感觉写的过于混乱,反而让初学者更糊涂,其实myeclipse6.0 连接和管理DB 是相当简单的,因为myeclipse6.0 的一些新功能使得它在这方面很大的方便了初学者去学习,很多初学者为了配置一个Eclipse 环境搞得焦头烂额,其实完全没有必要,任何的辅助工具都离不开它的核心思想,学习JAVA才是正题 ...........我们也进入正题
分三步走
1. 下载myeclipse
2 . 下载需要的DBMS 和 JDBC
3 . 配置
1. 下载myeclipse
自己下载 , 新手就下 All in one ,地址 GOOGLE 自己搜
2 . 下载需要的DBMS 和 JDBC
自己下载 , GOOGLE 自己搜
例子:mysql-5.0.45-win32.zip+ mysql-connector-java-5.1.5.zip
3 . 配置
Windows->show view->DB browser
New DataBase -> 弹出窗口DB Driver ->
自己选 DB module , 添加对应DBMS 的 JDBC (..JAR 文件)
DB -> open Connection
example:
new project , set buid path , copy the JDBC jar to current project , then add the build path
new a class named :Da.java
code as follow:
/**/
/* my study code for MYSQL*/
package
DAO;
import
java.sql.SQLException;
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
public
class
Da
...
{
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
/** *//**
* @param args
*/
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
public static void main(String[] args) ...{
// TODO Auto-generated method stub
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
try ...{
Class.forName("com.mysql.jdbc.Driver");
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
catch (ClassNotFoundException e)...{
e.printStackTrace();
}
java.sql.Connection conn = null; // connect
java.sql.Statement stmt = null; // description
java.sql.ResultSet rs = null; // result
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
try...{
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=GBK","root","123");
stmt = conn.createStatement();
stmt.executeUpdate("insert into userInfo(email,name) values ('za@za.com','zero')");
rs = stmt.executeQuery("select * from userInfo");
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
while(rs.next())...{
System.out.println("name "+rs.getString("name"));
System.out.println("email "+rs.getString("email"));
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
} catch(SQLException e)...{
e.printStackTrace();
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
finally ...{
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
try ...{
rs.close();
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
catch(SQLException e)...{
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
try ...{
stmt.close();
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
catch(SQLException e)...{
}
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
try...{
conn.close();
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
}catch(SQLException e)...{
}
}
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)