当前位置: 代码迷 >> Eclipse >> eclipse如何连mysql
  详细解决方案

eclipse如何连mysql

热度:37   发布时间:2016-04-23 14:20:29.0
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();
}
  相关解决方案