下面是我的代码:
import java.sql.*;public class TestJDBC { public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@172.19.135.21:1521:orcl","system","longtou19871020"); }}
上网查了很多资料,就是连不上,总会抛出下面的异常:
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
希望各位兄弟姐妹帮小弟一下,找出问题,谢谢!还有就是172.19.135.21是本机的ip吗?
import java.sql.*;public class TestJDBC { public static void main(String[] args) throws Exception {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@172.19.135.21:1521:orcl","system","longtou19871020"); }}
上网查了很多资料,就是连不上,总会抛出下面的异常:
Exception in thread "main" java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
希望各位兄弟姐妹帮小弟一下,找出问题,谢谢!还有就是172.19.135.21是本机的ip吗?
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.SQLException;public class FirstOracleJdbc
{
public static void main(String[] args)
{
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ldy", "ldy", "123");
st = con.createStatement();
String sql = "select * from student";
rs = st.executeQuery(sql);
while(rs.next())
{
System.out.print("id=" + rs.getInt("id"));
System.out.print(",name=" + rs.getString("name"));
System.out.print(",birthday=" + rs.getDate("birthday"));
}
}catch(Exception e)
{
e.printStackTrace();
}finally
{
try
{
rs.close();
}catch(Exception e)
{
}
try
{
st.close();
}catch(Exception e)
{
}
try
{
con.close();
}catch(Exception e)
{
}
}
}
}
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@127.0.0.1:1521:orcl","system","longtou19871020"); } } 另:保证要有驱动!
最大可能性是你的Oracle的侦听没有打开.你用sqlplus连接一下数据库,看能否正常连接.
其次确定你的驱动包放到了你的构建路径下
本机IP是127。0。0。1
Exception in thread "main" java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
127.0.0.1:1521:orcl这是什么意思啊?
解答1:我也遇到这个问题,但是幸运的是我刚刚解决。
错误码一样。你看看如下几个问题:
1、zzlt 是你的数据库名还是数据库的实例名。
比如我在SQL PLUS里面连接的是finance数据库实例,一切正常,但是Oracle的Url是 finance.ora,那么在端口后面就应该写ora而不是finance.
2、到你的Oracle数据上去看看,修改一下一个配置文件,具体文件我忘了,反正我把里面的ora全部换成了IP地址,然后通过,现在应用良好。
------------
解答2:
在 ORACLE 里用tnsping 看看listener启动了吗?
再看看listener config file 里面有没有写上你的SID
解答3:
到服务器上看一下,listener.ora
SID_LIST_LISTENER =
(SID_DESC =
(GLOBAL_DBNAME = oracle9i)
(ORACLE_HOME = /opt/oracle9i/product/9.2.0)
(SID_NAME = ORCL)
)
)
你的url里面可能用的是上面的GLOBAL_DBNAME 的值,就是用的是SERVICE_NAME, 替换成SID_NAME后面的值试试看
你可以用sqlplus登陆到服务器
$sqlplus / as sysdba
SQL> select * from v$instance;
看一下你的机器正在跑的SID的名字是什么