使用JDBC连接Oracle数据库:出现java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
这是我连接代码;
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<%--
使用myoracle数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver " ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:myoracle " ;
String DBUSER = "scott " ;
String DBPASSWORD = "tiger " ;
Connection conn = null ;
Statement stmt = null ;
%>
<%
try
{
Class.forName(DBDRIVER) ;
// 连接时必须填写用户名及密码
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
// 创建表的SQL语句
String sql = "CREATE TABLE mldntab (name varchar(20)) " ;
stmt = conn.createStatement() ;
stmt.executeUpdate(sql) ;
stmt.close() ;
conn.close() ;
}
catch(Exception e)
{
out.println(e) ;
}
%>
------解决方法--------------------------------------------------------
看下你的数据库服务以及数据库监听是否起来了?
------解决方法--------------------------------------------------------
<%@ page contentType= "text/html;charset=gb2312 "%>
<%@ page import= "java.sql.* "%>
<%--
使用myoracle数据库
用户名:scott
密码:tiger
--%>
<%!
String DBDRIVER = "oracle.jdbc.driver.OracleDriver " ;
String DBURL = "jdbc:oracle:thin:@localhost:1521:myoracle " ;
String DBUSER = "scott " ;
String DBPASSWORD = "tiger " ;
Connection conn = null ;
Statement stmt = null ;
%>
<%
try
{
Class.forName(DBDRIVER) ;
// 连接时必须填写用户名及密码
System.out.println( "连接前 ");
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD) ;
System.out.println( "连接后 ");
}
catch(Exception e)
{
out.println(e) ;
}
%>
语句应该没有问题
------解决方法--------------------------------------------------------
连接不上数据库服务器,估计ipc错误
------解决方法--------------------------------------------------------
看看是不是你这台机器上的数据库?
数据库SID是不是myoracle?
反正是你没连不上oracle