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