用JSP开发一网站,数据库用的是Oracle 10g
服务器用的是tomcat6.0。。
在数据库连接的时候就遇到困难了。
1、Oracle完全安装后,还需要哪些配置么?
2、对数据库用户有什么要求么?我用的是system用户连接代码:(转自:http://topic.csdn.net/u/20100607/11/a7a79b60-ec60-4dd0-86bf-379f59faa0e8.html?99653)
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*" %> 
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %> 
<html>
<head>
<title>Oracle数据库连接测试</title>
</head>
<body>
<% 
    java.sql.Connection lConn = null; 
    java.sql.Statement lStat = null; 
    java.sql.ResultSet lRs = null; 
    try 
    {      
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());  
String lUrl = "java:oracle:thin:@localhost:1521:orcl"; 
//java:oracle:thin: 表示使用的是thin驱动 
//@srv:1521: 表示使用的服务器的名字和端口号 
//dbname: 表示数据库的SID 
        lConn = DriverManager.getConnection(lUrl,"system","rg"); 
       lStat = lConn.createStatement(); //创建表 
String createTableCoffees = "CREATE TABLE COFFEES " + 
    "(COF_NAME VARCHAR(32), SUP_ID INTEGER, PRICE FLOAT, " + 
    "SALES INTEGER, TOTAL INTEGER)"; 
       lStat.executeUpdate(createTableCoffees); //插入数据 
lStat.executeUpdate("INSERT INTO COFFEES VALUES ('Colombian', 101, 7.99, 0, 0)"); 
lStat.executeUpdate("INSERT INTO COFFEES VALUES ('Espresso', 150, 9.99, 0, 0)"); 
lStat.executeUpdate("INSERT INTO COFFEES VALUES ('Colombian_Decaf', 101, 8.99, 0, 0)"); 
lStat.executeUpdate("INSERT INTO COFFEES VALUES ('French_Roast_Decaf', 49, 9.99, 0, 0)");    //查询结果 
lRs = lStat.executeQuery("select * from COFFEES"); //显示结果 
      out.println("<table>"); 
       
       while (lRs.next()) { 
        out.print("<tr><td>" + lRs.getString(1)); 
//COF_NAME 
out.print(  "<td>" + lRs.getInt(2)); 
//SUP_ID 
out.print(  "<td>" + lRs.getFloat(3)); 
//PRICE 
out.print(  "<td>" + lRs.getInt(4)); 
//SALES 
out.println(  "<td>" + lRs.getInt(5)); 
//TOTAL 
       }        out.println("</table>"); lRs.close(); 
       lStat.close(); 
    } catch (SQLException e) { 
      throw new ServletException(e); 
    } finally { 
      try { 
        if (lConn != null) 
          lConn.close(); 
      } catch (SQLException e) { 
      } 
    } 
%>
</body>
</html>
-----------------------------------------------------------------------------------------------------
出错信息:
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: javax.servlet.ServletException: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause javax.servlet.ServletException: java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
org.apache.jsp.oracle_jsp._jspService(oracle_jsp.java:115)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause java.sql.SQLException: Io 异常: The Network Adapter could not establish the connection
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:254)
oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:386)
oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:413)
oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:164)
oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:34)
oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:752)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:185)
org.apache.jsp.oracle_jsp._jspService(oracle_jsp.java:76)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.请各位大侠帮忙看看,先谢过了

解决方案 »

  1.   

    请确保orcl是你要连接的本机数据库的ORACLE_SID值
    另外,用户密码system/rg是正确的。
    localhost如果不行,可以试一下本机的机器名或者IP地址。telnet <本机IP> 1521
    可以成功运行吗?
      

  2.   

    先确认配置好了TNS.然后用其它第三方工具连接下,看是否可以,
    然后再用JDBC连接,这样就可以排除ORACLE端出现的问题
    把关注点转移到程序上来
      

  3.   

    我感觉还是Oracle配置方面的问题试了好几个连接都没成功用了个连接工具也没连成功请问Oracle安装后需要哪些配置呢?
      

  4.   

    好了,连接上了。。是本地net服务名配置出现了问题感谢各位的帮助