package Disease1;
import java.sql.*;
import java.lang.String;
//数据库连接
public class benchmark {
Statement stmt=null ;
ResultSet rs=null ;
public Connection getConn() throws Exception {
Connection conn = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://MICROSOF-1F1693:1433;DatabaseName=BecheDisease;user=sa;password=******");
}catch (SQLException e) {
e.printStackTrace();
}
return conn;
}
public void Exec(String sql){//执行sql语句
try{
getConn();
stmt.executeUpdate(sql);
}catch(Exception e){
System.out.print("exec=="+e);
}
}
public ResultSet getRs(String sql)throws SQLException {//获取查询语句集对象
try{ getConn();
rs=stmt.executeQuery(sql);
return rs; }
catch(Exception e){
System.out.print(e);
return null; }}
}
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="java.sql.*"%>
<jsp:useBean id="getConn" scope="page" class="Disease1.benchmark" />
<%
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>
<title>海参疾病诊断查询</title>
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="content-language" content="en-gb" />
<link rel="stylesheet" type="text/css" href="fund.css">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<script language="JavaScript">
</script>
<body><form>
<div class="topic">
<div class="topicBox">
<table align=center width=100% border="0"
style="border-bottom: 1px solid #aaaaaa; margin: 0px 0px 8px 8px;">
<tr><td><h3>请选择海参病变症状</h3></td></tr>/table>
<table width=100% align=center border=0>
<%String sql = "select Symptom from Symptom_table ";
ResultSet rs = getConn.getRs(sql);
int intMax=0;
while(rs.next()){
intMax++;
}rs.close();
String[] Symptom=new String[intMax];
rs = getConn.getRs(sql);
if(intMax>0){
int i=0;
while (rs.next()) {
String Symp=rs.getString(2);
Symptom[i]=Symp;
i++;
rs.close();
}else{rs.close();}
%>
<tr><td valign=top align=left>
<% for (int i = 0; i < Symptom.length; i++) { %>
<input name="Symptom" type="checkbox" />
<option value=<%= i %>><%=Symptom[i]%></option>
<%
}
%>
</td>
</tr>
</table>
</div></div>
</form><br></body>
</html>
错误信息
description The server encountered an internal error () that prevented it from fulfilling this request.
exception org.apache.jasper.JasperException: An exception occurred processing JSP page /search.jsp at line 53
50:String sql = "select Symptom from Symptom_table ";
51:ResultSet rs = getConn.getRs(sql);
52:int intMax=0;
53:while(rs.next()){
54:intMax++;
55:}rs.close();
56:String[] Symptom=new String[intMax];
jsp连接数据库问题(在线等!!!)
答案:3 悬赏:0 手机版
解决时间 2021-12-21 22:12
- 提问者网友:战魂
- 2021-12-20 22:09
最佳答案
- 五星知识达人网友:怙棘
- 2022-01-10 01:57
rs应该是等于null
如果rs等于0就不会报错了
检查一下数据库连接是否正确
如果rs等于0就不会报错了
检查一下数据库连接是否正确
全部回答
- 1楼网友:骨子里都是戏
- 2022-01-10 03:38
首先楼主应该先检查一下是否能获得与数据库的连接
如能
在第52行前打印一下rs看出来的是什么?
- 2楼网友:山君与见山
- 2022-01-10 02:59
javabean是不应该连接数据库的。
作个简单的判断就可以了,如果传进来的值==空,这个数据不要,不放到bean中就可以了(set)!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯