连接数据库 rs.next() 报错
RT:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page import="java.sql.*" %>
<%@page import="pc.DBHelper"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'newsList.jsp' starting page</title>
</head>
<jsp:useBean id="Conn" class="pc.DBHelper"/>
<body>
<table width="200" cellspacing="1" cellpadding="1">
<tr>
<td>ID</td>
<td>名称</td>
</tr>
<% ResultSet rs1 = Conn.getResultSet("select * from news quot"); %>
<% while(rs1.next())
{%>
<tr>
<td><%= rs1.getInt("id")%></td>
<td><%= rs1.getString("content")%></td>
</tr>
<%} %>
</table>
</body>
</html>
页面
package pc;
import java.sql.*;
public class DBHelper
{
static final String DriverName="com.mysql.jdbc.Driver"; //driver
static final String dbURL="jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=GBK";
public static Connection getConnection()
{
Connection conn = null;
try
{
Class.forName(DriverName);
conn = DriverManager.getConnection(dbURL,"root","root"); //conn object
}
catch (Exception e){}
return conn;
}
public static void Close(Connection conn)
{
try //conn close
{
if(conn!=null)
conn.close();
}
catch(Exception e){}
}
public void Close(ResultSet rs) //resultset close
{
try
{
if(rs!=null)
rs.close();
}
catch(Exception e){}
}
public void Close(Statement operation) //statement close
{
try
{
if(operation!=null)
operation.close();
}
catch(Exception e){}
}
public ResultSet getResultSet(String st)
{
try
{
Statement operation1 = DBHelper.getConnection().createStatement();
ResultSet rs1 = operation1.executeQuery(st);
return rs1;
}
catch (Exception e)
{}
return null;
}
public int getexecuteUpdate(String st)
{
int i = -1;
try
{
Statement stmt = (DBHelper.getConnection()).createStatement();
i = stmt.executeUpdate(st);
return i;
}
catch (Exception e)
{e.printStackTrace();}
return i;
}
}
.java
为什么 rs.next()报错?
------解决方案--------------------
Java code
public final class JdbcUtilsSing {
private String url = "jdbc:mysql://localhost:3306/jdbc";
private String user = "root";
private String password = "";
// private static JdbcUtilsSing instance = new JdbcUtilsSing();
private static JdbcUtilsSing instance = null;
private JdbcUtilsSing() {
}
public static JdbcUtilsSing getInstance() {
if (instance == null) {
synchronized (JdbcUtilsSing.class) {
if (instance == null) {
instance = new JdbcUtilsSing();
}
}
}
return instance;
}
static {
try {
Class.forName("co