我正在嘗試建立到遠程mysql數據庫的連接。我已經將jar連接器放到了war/WEB-INF/lib
文件夾中並添加了一個庫(構建路徑)。連接上的MySQL JDBC錯誤
不過我收到此錯誤:
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倍!
什麼是'sql4.freemysqlhosting.net'? –
它是數據庫的主機 – vlio20