菜鸟
请牛人速答 不胜感激
<%@ 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
请牛人速答 不胜感激
<%@ 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
解决方案 »
- 谁有最新的oracle CHM格式的中文帮助文档?
- DBA_TABLESPACES中的SEGMENT_SPACE_MANAGEMENT字段是什么意思?
- ORACLE 根据一个字段的值得到下面的结果如何写sql
- oracle条件导入
- 如何取消Create_Record?
- 请问如何在存储过程中使用参照对象类型
- oracle的home版有什么不同啊
- 高手来拿分:ora-03113 通信通道的文件结束
- OracleOraHomeClientCache这个服务是做什么用的?
- 两台服务器,要访问同一个磁盘阵列,是不是必须做windows集群?
- 使用data link 连接远程数据库同步遇到的问题
- 急!在线等!Oracle不识别从SQL Server导入的表格问题!
你先tnsping myoracle看通不通
通的话用sqlplus scott/tiger@myoracle看能连不
能的话,把localhost换成ip
<%@ 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
TBSPING 显示OK
SQLPLUS也能连接
select instance_name from v$instance;
查询出sid
然后把
jdbc:oracle:thin:@192.168.0.202:myoracle
换成
jdbc:oracle:thin:@192.168.0.202:1521:sid
试一下