jdbc连接oracle11g数据库 报错。 求找错!!
java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:414)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at org.accp.test.Test.main(Test.java:19)
代码:
static Connection conn;
static PreparedStatement stm;
static ResultSet rs;
static String driver="oracle.jdbc.driver.OracleDriver";
static String url="jdbc:oracle:thin:@localhost:1521:ORCL";
public static void main(String[] args) {
try {
Class.forName(driver);
Connection ct = DriverManager.getConnection(url, "us", "us");
String sql="select * from person";
stm = ct.prepareStatement(sql);
rs=stm.executeQuery();
while(rs.next())
{
System.out.println("用户名:"+rs.getString(1));
}
} catch (
ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (
SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
------解决方案--------------------
static String url="jdbc:oracle:thin:@localhost:1521:ORCL";
localhost 换成计算机名?