您的位置:首页 > 编程语言 > Java开发

myeclipse6.0 连接和管理DB

2008-01-11 16:50 176 查看
最近看了几篇关于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;




public class Da ...{




/** *//**


* @param args


*/




public static void main(String[] args) ...{


// TODO Auto-generated method stub




try ...{


Class.forName("com.mysql.jdbc.Driver");


}




catch (ClassNotFoundException e)...{


e.printStackTrace();


}


java.sql.Connection conn = null; // connect


java.sql.Statement stmt = null; // description


java.sql.ResultSet rs = null; // result






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");




while(rs.next())...{




System.out.println("name "+rs.getString("name"));


System.out.println("email "+rs.getString("email"));


}




} catch(SQLException e)...{


e.printStackTrace();


}




finally ...{




try ...{


rs.close();


}




catch(SQLException e)...{


}




try ...{


stmt.close();


}




catch(SQLException e)...{


}




try...{


conn.close();




}catch(SQLException e)...{


}


}


}


}













内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: