我正在尝试建立与远程 mysql 数据库的连接。我已将 jar 连接器放入war/WEB-INF/lib
文件夹并添加了一个库(构建路径)。
我仍然收到此错误:
java.sql.SQLException: No suitable driver found for jdbc:sql4.freemysqlhosting.net
at java.sql.DriverManager.getConnection(Unknown Source)
这是完整的代码:
/**
*
*/
package com.infograph.dbconnection;
import java.sql.DriverManager;
import java.sql.Connection;
import java.sql.SQLException;
/**
* @author Vlad
*
*/
public class DBConnection
{
/**
*
*/
public DBConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
}
catch (ClassNotFoundException e)
{
System.out.println("Where is your MySQL JDBC Driver?");
e.printStackTrace();
return;
}
System.out.println("MySQL JDBC Driver Registered!");
Connection connection = null;
try
{
connection = DriverManager.getConnection("jdbc:sql4.freemysqlhosting.net","user", "pass");
}
catch (SQLException e1)
{
System.out.println("Connection Failed! Check output console");
e1.printStackTrace();
return;
}
if (connection != null)
{
System.out.println("You made it, take control your database now!");
}
else
{
System.out.println("Failed to make connection!");
}
}
}
问题是什么??10倍!