jsp 远程连接 oracle 出错
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="oracle.jdbc.*"%><!-- 导入ojdbc14.jar -->
<%@ 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 'index.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" mce_href="styles.css">
-->
</head>
<body>
<%
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
ResultSet rs=null;
String oraUrl="jdbc:oracle:thin:@127.0.0.1:1521:xtweb";//jdbc:oracle:thin:@localhost:1521:xtweb
String oraUser="xtweb";
String oraPWD="xtweb";
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
} catch (SQLException e)
{
out.print("数据库连接驱动出错!");
}
try
{
Connection conn=DriverManager.getConnection(oraUrl,oraUser,oraPWD);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
rs=stmt.executeQuery("select * from T_TEST");
while(rs.next())
{
out.print(rs.getString("ID"));
out.print(":");
out.print(rs.getString("NAME"));
out.print("<br>");
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException e)
{
System.out.println(e.toString());
out.print(e.toString());
}
%>
</body>
</html>
报错页面错误信息截取:
An error occurred at line: 33 in the jsp file: /test.jsp
oracle.jdbc.driver.OracleDriver cannot be resolved to a type
30: String oraPWD="xtweb";
31: try
32: {
33: DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
34: } catch (SQLException e)
35: {
36: out.print("数据库连接驱动出错!");
请问如何解决? --------------------编程问答-------------------- 这年头还有在jsp页面直接写java代码的啊?数据库连接步骤
1.加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver")
2.Connection conn=DriverManager.getConnection(oraUrl,oraUser,oraPWD); --------------------编程问答-------------------- 你无视我的代码啊,这两个都已经存在我代码里了。26行和40行。 --------------------编程问答-------------------- 有人了解吗? --------------------编程问答-------------------- 既然是远程连接怎么还是127.0.0.1 --------------------编程问答-------------------- 去掉,貌似如一楼所说
try
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
} catch (SQLException e)
{
out.print("数据库连接驱动出错!");
}
补充:Java , Web 开发