一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jsp/javabean分页列出数据

时间:2022-07-02 18:13:35 编辑:袖梨 来源:一聚教程网

我的第一个jsp分页代码
jsp文件:pagedata.jsp //显示数据
javabean:DataConn.java //连接数据库
javabean:GetCount.java //获得数据记录数
DataConn.java文件内容:
package aliang_org;
import java.sql.*;
public class DataConn{
public static Connection getDataConn() {
Connection conn = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=your","your","your");
}
catch(Exception ex) {
ex.printStackTrace();
}
return conn;
}
}
GetCount .java文件内容:
package aliang_org;
import java.sql.*;
import java.util.*;
import java.io.*;
public class GetCount {
private Connection conn;
public GetCount()throws Exception{
conn = DataConn.getDataConn();
}
public int getCounter()throws Exception{
int ret = 0;
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select count(*) from UserInfos");
while(rset.next()){
ret = rset.getInt(1);
}
return ret;
}
}
pagedata.jsp 文件内容:
<%@ page contentType="text/html; charset=gb2312" language="java"%>
<%@ page import = "aliang_org.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.sql.*"%>


<br />jsp/Java</a>Bean分页列出数据<br />


jsp/JavaBean分页列出数据





热门栏目