连接不上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