【发布时间】:2014-06-02 15:39:49
【问题描述】:
我在连接 java 和 mysql 数据库时遇到问题,昨天工作正常,但现在无法正常工作,这是我的代码。
public static void main(String[] args) {
try
{
Class.forName ("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println ("Could not load the driver");
}
String user, pass, host, database;
user = "Michael";
pass = "Blaine22";
host = "localhost";
database = "maintenance_work";
Connection conn = DriverManager.getConnection
("jdbc:mysql://"+host+":3306/"+database, user, pass);
conn.setAutoCommit(false);
//Menu code:
appSchoolMaintenance newWork = new appSchoolMaintenance();
newWork.statement1(); // opens the start method
}
【问题讨论】:
-
大约十年来您不需要 Class.forName() 行。只需将其删除。然后您可能会遇到另一个错误,或者再次出现相同的错误,但这次至少您将运行最新的代码。
-
@EJP> 你们提供连接池吗?
-
这正是您昨天运行的项目吗?
-
你把 jar 添加到你的库了吗?
-
@mok 你到底在说什么?我提供许多产品和服务,但连接池不是其中之一。
标签: java mysql dbconnection