首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

eclipse如何连mysql

2012-01-09 
eclipse怎么连mysql如题[解决办法]下载 连接mysql的jar 包,如:mysql-connector-java-5.0.4-bin.jar把jar包

eclipse怎么连mysql
如题

[解决办法]
下载 连接mysql的jar 包,如:mysql-connector-java-5.0.4-bin.jar
把jar包加入到你的项目中.
以下是连接代码

try {
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading MySQL Driver...");
} catch (Exception ex) {
System.out.println("Error loading MySQL Driver...");
ex.printStackTrace();
}
try {
conn = DriverManager
.getConnection("jdbc:mysql://localhost:3306/数据库名?user=root&password=密码");
System.out.println("Success connect Mysql Database!"); 
} catch (Exception e) {
e.printStackTrace();
}

热点排行