日期:2014-05-20 浏览次数:20844 次
import java.sql.Connection; import java.sql.DriverManager; public class conn_demo { //数据库驱动程序名 public static final String DBDRIVER = "oracle.jdbc.driver.OracleDriver"; //数据库地址 public static final String DBURL = "jdbc:oracle:thin:@localhost:1521:192.168.1.102"; //数据库用户名 public static final String DBUSER = "scott"; //数据库密码 public static final String DBPASS = "tiger"; public static void main(String[] args){ try{ Connection conn = null; //加载数据库 Class.forName(DBDRIVER).newInstance(); //连接数据库 conn = DriverManager.getConnection(DBURL, DBUSER, DBPASS); System.out.println(conn); //关闭数据库 conn.close(); }catch(Exception e){ e.printStackTrace(); } }
java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:254) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386) at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:438) at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164) at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34) at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at conn_orcl.conn_demo.main(conn_demo.java:22)