jsp连Oracle 数据库。进来看看代码哪错了
从网上抄的代码。新手。
<%--@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"--%>
<%@ page contentType="text/html;charset=GB2312" language="java" %>
<%@ 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">
-->
</head>
<body>
Hello World2 . <br>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@127.0.0.1:1521:ORACLE";
String user="ddyy";
String password="his";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from zgzb";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
发<%=rs.getString(1)%>
bb<%=rs.getString(2)%>
<%}%>
<%out.print("sss!");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
------解决方案--------------------String url="jdbc:oracle:thin:@127.0.0.1:1521:ORACLE";
你确定你的数据库实例是ORACLE吗?不是orcl?
------解决方案--------------------看看错误信息是什么。
其实基本上用不带参数的就行了,也就是相当于:
createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY)
性能也最好。
------解决方案--------------------能说抛什么异常么?
------解决方案--------------------检查一下SID是否一致。。