import java.sql.*;
public class Connect
{
public static void main (String[] args)
{
Connection conn = null;
try
{
String userName = "root";
String password = "password123!";
String url = "jdbc:oracle:thin:@localhost:3306:procomport";
//Class.forName ("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection(url, userName, password);
//Connection connection = DriverManager.getConnection(url , userName, password);
System.out.println ("Database connection established");
}
catch (Exception e)
{
System.err.println ("Cannot connect to database server");
}
finally
{
if (conn != null)
{
try
{
conn.close();
System.out.println ("Database connection terminated");
}
catch (Exception e) { /* ignore close errors */ }
}
}
}
}
這是我的代碼我有多個不同的數據庫,但它不會連接到它們中的任何一個這是什麼問題?我一直收到它無法連接到數據庫的錯誤。雖然我可以使用其他管理工具連接到它,但它是驅動程序問題?我如何能夠判斷我是否有必要的驅動程序?Java不會連接到數據庫無論是什麼驅動程序
你得到了什麼確切的錯誤?打印出異常,最好還是打印異常的堆棧跟蹤。 – 2012-07-08 04:37:42
你的類路徑中有「瘦」的驅動程序? – 2012-07-08 07:09:56