当前位置: 技术问答>java相关
客户端连接oracle服务器!!
来源: 互联网 发布时间:2015-05-04
本文导语: import java.sql.*; 本地只有oracle驱动classes12.zip 现在classpath已经没有问题了。但是 执行以后的出错信息如下 ddddddIo 异常: The Network Adapter could not establish the connectionException in thread "main" java.lang.NullPointerException ...
import java.sql.*;
本地只有oracle驱动classes12.zip
现在classpath已经没有问题了。但是
执行以后的出错信息如下
ddddddIo 异常: The Network Adapter could not establish the connectionException in thread "main" java.lang.NullPointerException
at conndb.main(conndb.java:30)
public class conndb
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
Connection conn=null;
Statement stmt=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(java.lang.ClassNotFoundException e){
System.err.println("aaaaa"+e.getMessage());
}
try{
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.150.6.168:1521:hotmail","scott","tiger");
}catch(SQLException e){
System.err.print("dddddd"+ e.getMessage());
}
stmt=conn.createStatement();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
}
}
本地只有oracle驱动classes12.zip
现在classpath已经没有问题了。但是
执行以后的出错信息如下
ddddddIo 异常: The Network Adapter could not establish the connectionException in thread "main" java.lang.NullPointerException
at conndb.main(conndb.java:30)
public class conndb
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
Connection conn=null;
Statement stmt=null;
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
}catch(java.lang.ClassNotFoundException e){
System.err.println("aaaaa"+e.getMessage());
}
try{
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.150.6.168:1521:hotmail","scott","tiger");
}catch(SQLException e){
System.err.print("dddddd"+ e.getMessage());
}
stmt=conn.createStatement();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
}
}
|
建议你把oracle安装目录下的jdbc目录下的jar、zip放入classpath,你如果用jbuilder开发的话,加入Libraries...中,其放置路径为:
../oracle/ora81/jdbc/lib/*.zip或*.jar;
另外还有可能使oracle的datasource server未启动引起!
../oracle/ora81/jdbc/lib/*.zip或*.jar;
另外还有可能使oracle的datasource server未启动引起!
|
try{
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.150.6.168:1521:hotmail","scott","tiger");
stmt=conn.createStatement();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
}catch(SQLException e){
System.err.print("dddddd"+ e.getMessage());
}
看看打印出来的是什么?
检查一下你的classpath!
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.150.6.168:1521:hotmail","scott","tiger");
stmt=conn.createStatement();
// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");
}catch(SQLException e){
System.err.print("dddddd"+ e.getMessage());
}
看看打印出来的是什么?
检查一下你的classpath!