连接不上ORACLE

javaxuexizhe123 2009-08-06 10:17:53
菜鸟
请牛人速答 不胜感激


<%@ 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
...全文
47 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shiyiwan 2009-08-06
  • 打赏
  • 举报
回复
catch里面把错误打出来再贴上来吧。
  • 打赏
  • 举报
回复
本地的服务......
你先tnsping myoracle看通不通
通的话用sqlplus scott/tiger@myoracle看能连不
能的话,把localhost换成ip
  • 打赏
  • 举报
回复
用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
试一下
javaxuexizhe123 2009-08-06
  • 打赏
  • 举报
回复
tnsping 命令显示OK
SQLPLUS也能连接
javaxuexizhe123 2009-08-06
  • 打赏
  • 举报
回复
试了二楼的意见
TBSPING 显示OK
javaxuexizhe123 2009-08-06
  • 打赏
  • 举报
回复
<%@ 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

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧