首先说明,数据库连接没有错 就是写JSP的时候 我遍历数据库的时候 他要按照数据库中的字段的从左到右的顺序读数据才行,不能查询2个同样的字段,必须要按照从左到右的顺序读。即使加上ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE这句话 也不起作用 就是数据库指针回滚的问题
先看一下 JSP的代码吧
<%
ResultSet rs=db.getResult("select * from Ipod_Users order by Ipod_Users_ID desc");
while(rs.next())
{
ID=rs.getInt("Ipod_Users_ID");
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="table_hui-Top">
<tr>
<td width="9%" height="30" class="black12" style="padding-left:15px"><%=rs.getInt("Ipod_Users_ID")%></td>
<td width="2%" class="black12"> </td>
<td width="21%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Name")%></td>
<td width="2%" class="black12"> </td>
<td width="5%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Sex")%></td>
<td width="2%" class="black12"> </td>
<td width="42%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Restime")%></td>
<td width="1%" class="black12"> </td>
<td width="16%" align="center" valign="middle" class="gray12"><a href="Admin_Delete_User.jsp?ID=<%=rs.getInt("Ipod_Users_ID")%>" class="blue12link"><img src="images/Delete_B.png" border="0px" onmouseover="Delete2(this)" onmouseout="Delete1(this)" onClick="return confirm('您确定要删除吗?');"/></a></td>
</tr>
</table>
<%
}
db.close();
%>
数据库代码
package DataBase;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
public class DB
{
Connection con;
ResultSet rs;
Statement stmt;
public Connection huodelianjie()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//------------------------连接数据库的驱动字符串。
con=DriverManager.getConnection("jdbc:odbc:IpodShop","sa","");
}
catch(SQLException e1)
{
System.out.println(e1+"\n数据库链接不正确!");
}
catch(Exception e2)
{
System.out.println(e2+"\n发生错误!");
}
return con;
}
//查询操作
public ResultSet getResult(String sql)
{
try
{
stmt=this.huodelianjie().createStatement(); //----------------------获得Statement对象
rs=stmt.executeQuery(sql);
}
catch(SQLException e3)
{
System.out.println(e3+"\n数据库链接不正确!");
}
return rs;
}
//查询以外的操作
public void excuteSql(String sql)
{
try
{
stmt = this.huodelianjie().createStatement();
stmt.execute(sql);
} catch (SQLException e) {
System.out.println("Excute SQL is Error.......");
System.out.println(e);
}
}
public void close()
{
try
{
if(!con.isClosed())
{
rs.close();
con.close();
stmt.close();
}
}
catch(SQLException e)
{
System.out.println(e+"关闭连接出错!");
}
}
}
根据回答的程度加分,只要能按照我写的那个JSP页面查询出来就给高分
先看一下 JSP的代码吧
<%
ResultSet rs=db.getResult("select * from Ipod_Users order by Ipod_Users_ID desc");
while(rs.next())
{
ID=rs.getInt("Ipod_Users_ID");
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="table_hui-Top">
<tr>
<td width="9%" height="30" class="black12" style="padding-left:15px"><%=rs.getInt("Ipod_Users_ID")%></td>
<td width="2%" class="black12"> </td>
<td width="21%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Name")%></td>
<td width="2%" class="black12"> </td>
<td width="5%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Sex")%></td>
<td width="2%" class="black12"> </td>
<td width="42%" align="left" valign="middle" class="black12"><%=rs.getString("Ipod_Users_Restime")%></td>
<td width="1%" class="black12"> </td>
<td width="16%" align="center" valign="middle" class="gray12"><a href="Admin_Delete_User.jsp?ID=<%=rs.getInt("Ipod_Users_ID")%>" class="blue12link"><img src="images/Delete_B.png" border="0px" onmouseover="Delete2(this)" onmouseout="Delete1(this)" onClick="return confirm('您确定要删除吗?');"/></a></td>
</tr>
</table>
<%
}
db.close();
%>
数据库代码
package DataBase;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
public class DB
{
Connection con;
ResultSet rs;
Statement stmt;
public Connection huodelianjie()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//------------------------连接数据库的驱动字符串。
con=DriverManager.getConnection("jdbc:odbc:IpodShop","sa","");
}
catch(SQLException e1)
{
System.out.println(e1+"\n数据库链接不正确!");
}
catch(Exception e2)
{
System.out.println(e2+"\n发生错误!");
}
return con;
}
//查询操作
public ResultSet getResult(String sql)
{
try
{
stmt=this.huodelianjie().createStatement(); //----------------------获得Statement对象
rs=stmt.executeQuery(sql);
}
catch(SQLException e3)
{
System.out.println(e3+"\n数据库链接不正确!");
}
return rs;
}
//查询以外的操作
public void excuteSql(String sql)
{
try
{
stmt = this.huodelianjie().createStatement();
stmt.execute(sql);
} catch (SQLException e) {
System.out.println("Excute SQL is Error.......");
System.out.println(e);
}
}
public void close()
{
try
{
if(!con.isClosed())
{
rs.close();
con.close();
stmt.close();
}
}
catch(SQLException e)
{
System.out.println(e+"关闭连接出错!");
}
}
}
根据回答的程度加分,只要能按照我写的那个JSP页面查询出来就给高分
换个数据库(如果你用access的话),换个连接方式吧!