[英]how to connect mysql database to desktop java application using jdbc?
how to connect mysql database to desktop java application using jdbc ? 如何使用jdbc将mysql数据库连接到桌面Java应用程序? the environment is ubuntu 12.04 Lts i tried so many ways but all of them throw an exception on executing
环境是ubuntu 12.04我尝试了很多方法,但是所有方法在执行时都会引发异常
Class.forName("com.mysql.jdbc.Driver");
the exception say : 例外说:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
the full code is : 完整的代码是:
import java.sql.*;
public class CRUDForGoods {
private Connection connection ;
public Vector<GoodsStore> goods ;
public CRUDForGoods(){
try{
DriverManager.registerDriver(new JdbcOdbcDriver());
connection = DriverManager.getConnection("jdbc:odbc:dbName","root", "root");
}
catch(Exception ex) {
System.out.println("##connection");
ex.printStackTrace();
}
}
com.mysql.jdbc.Driver
not found while executing the code. 执行代码时未找到
com.mysql.jdbc.Driver
。
You need mysql connector to get it run (the jar includes com.mysql.jdbc.Driver
). 您需要mysql连接器才能使其运行(jar包含
com.mysql.jdbc.Driver
)。 You can find it here 你可以在这里找到
Download and include the jar file in your classpath. 下载jar文件并将其包含在您的类路径中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.