JSP 连接Oracle数据库, 哪里错了?
<%@pagecontentType="text/html;charset=gb2312"%><%@pageimport="java.sql.*"%><html><bod...
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@192.168.1.37:1521:DM863";
//orcl为你的数据库的SID
String user = "bpeluser";
String password = "bpeluser";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from CLASSIFY";
rs = stmt.executeQuery(sql);
while (rs.next()) {
%>
您的第一个字段内容为:<%=rs.getInt(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%
}
%>
<%
out.print("数据库操作成功,恭喜你");
%>
<%
}
catch (Exception ex) {
ex.printStackTrace();
}
%>
<%
finally {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
conn.close();//关闭连接
}
%>
</body>
</html>
报错:
An error occurred at line: 35 in the jsp file: /orctest.jsp
Syntax error, insert "}" to complete Block
An error occurred at line: 38 in the jsp file: /orctest.jsp
rs cannot be resolved
An error occurred at line: 40 in the jsp file: /orctest.jsp
stmt cannot be resolved
An error occurred at line: 36 in the jsp file: /orctest.jsp
conn cannot be resolved 展开
<%@ page import="java.sql.*"%>
<html>
<body>
<%
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url = "jdbc:oracle:thin:@192.168.1.37:1521:DM863";
//orcl为你的数据库的SID
String user = "bpeluser";
String password = "bpeluser";
conn = DriverManager.getConnection(url, user, password);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
String sql = "select * from CLASSIFY";
rs = stmt.executeQuery(sql);
while (rs.next()) {
%>
您的第一个字段内容为:<%=rs.getInt(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%
}
%>
<%
out.print("数据库操作成功,恭喜你");
%>
<%
}
catch (Exception ex) {
ex.printStackTrace();
}
%>
<%
finally {
if (rs != null)
rs.close();
if (stmt != null)
stmt.close();
conn.close();//关闭连接
}
%>
</body>
</html>
报错:
An error occurred at line: 35 in the jsp file: /orctest.jsp
Syntax error, insert "}" to complete Block
An error occurred at line: 38 in the jsp file: /orctest.jsp
rs cannot be resolved
An error occurred at line: 40 in the jsp file: /orctest.jsp
stmt cannot be resolved
An error occurred at line: 36 in the jsp file: /orctest.jsp
conn cannot be resolved 展开
3个回答
展开全部
用这个试试:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为你的数据库的SID
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<html>
<body>
<%Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
String url="jdbc:oracle:thin:@localhost:1521:orcl"; //orcl为你的数据库的SID
String user="scott";
String password="tiger";
Connection conn= DriverManager.getConnection(url,user,password);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from test";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()) {%>
您的第一个字段内容为:<%=rs.getString(1)%>
您的第二个字段内容为:<%=rs.getString(2)%>
<%}%>
<%out.print("数据库操作成功,恭喜你");%>
<%rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
少个大括号
把所有的数据库操作都放入一个trycatch中 根本不会查出 哪一步报告的异常
判断应该就是没有连接上
把所有的数据库操作都放入一个trycatch中 根本不会查出 哪一步报告的异常
判断应该就是没有连接上
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你看看你写的程序 不是少个大括号 就是多个大括号 你好好看看
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询