菜鸟   
请牛人速答     不胜感激
<%@ page language="java" import="java.util.*" %>
<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*" %><%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'connect.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>  
  <body>
<%
 //获取用户名
 String username = request.getParameter("username");
 //获取密码
 String password = request.getParameter("password");
 //连接数据库
try
{
 Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch(ClassNotFoundException e)
{
   e.printStackTrace();
}
try
{
 String url="jdbc:oracle:thin:@localhost:myoracle";
 Connection con=DriverManager.getConnection(url, "scott", "tiger");
 Statement sql=con.createStatement();
 String sql1="select * from text ";
 ResultSet rs = sql.executeQuery(sql1);     
     
   if(rs.next())
   { out.print("连接成功!");}
   else
   {  out.print("连接失败");}
     
  }
 catch(SQLException   e)
           {   
            System.out.println("sorry,Can't   connect   to   oracle");   
            }    
%>
<p> welcome to my page
  </body>
</html>TOMCAT 提示:sorry,Can't   connect   to   oracle

解决方案 »

  1.   

    本地的服务......
    你先tnsping myoracle看通不通
    通的话用sqlplus scott/tiger@myoracle看能连不
    能的话,把localhost换成ip
      

  2.   

    catch里面把错误打出来再贴上来吧。
      

  3.   

    <%@ page language="java" import="java.util.*" %>
    <%@ page contentType="text/html;charset=GB2312"%>
    <%@ page import="java.sql.*" %><%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'connect.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>  
      <body>
    <%
     //获取用户名
     String username = request.getParameter("username");
     //获取密码
     String password = request.getParameter("password");
     //连接数据库
    try
    {
     Class.forName("oracle.jdbc.driver.OracleDriver");
    }
    catch(ClassNotFoundException e)
    {
       e.printStackTrace();
    }
    try
    {
     String url="jdbc:oracle:thin:@192.168.0.202:myoracle";
     Connection con=DriverManager.getConnection(url, "scott", "tiger");
     Statement sql=con.createStatement();
     String sql1="select * from text ";
     ResultSet rs = sql.executeQuery(sql1);     
         
       if(rs.next())
       { out.println("连接成功!");}
       else
       {  out.println("连接失败");}
         
      }
     catch(SQLException   e)
               {   
                System.out.println("sorry,Can't   connect   to   oracle");   
                }    
    %>
    <p> welcome to my page
      </body>
    </html>
    TOMCAT信息
    信息: Server startup in 1949 ms
    sorry,Can't   connect   to   oracle
    sorry,Can't   connect   to   oracle
    sorry,Can't   connect   to   oracle
    sorry,Can't   connect   to   oracle
      

  4.   

    试了二楼的意见
    TBSPING 显示OK
      

  5.   

    tnsping 命令显示OK
    SQLPLUS也能连接
      

  6.   

    用sqlplus /as sysdba连接后,
    select instance_name from v$instance;
    查询出sid
    然后把
    jdbc:oracle:thin:@192.168.0.202:myoracle
    换成
    jdbc:oracle:thin:@192.168.0.202:1521:sid
    试一下