userlist.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<%
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage"
;
if(pages==null)
{
pages="1";
}
try
{
dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
%>
<%
Connection con;
Class.forName("dm4.jdbc.driver.Dm4Driver"
.newInstance();
String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con= DriverManager.getConnection(url,name,password);
Statement sqlStmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sqlQuery="select * from userinfo";
ResultSet rs=sqlStmt.executeQuery(sqlQuery);
rs.beforeFirst();
rs.last();//移动到最后一行的行号
//int rowNumber=rs.getRow();//得到最后一行的行号
int countRecord=0;//记录条数
int countPage=0;//总页数
int countPageRecord=5;//每页3条记录,要设置每页记录条数就更改这个变量的值
countRecord=rs.getRow();//得到总页数
if(countRecord/countPageRecord==0)
countPage=countRecord/countPageRecord;
else
countPage=countRecord/countPageRecord+1;
//把记录指针移至当前页第一条记录之前
if((dipage-1)*countPageRecord==0)
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%>
<form action="userinsert.jsp" method="post" name="form1">
<table align="center">
<tr>
<td>
姓名:
</td>
<td>
<input type="text" size="10" name="name">
</td>
<td>
年龄:
</td>
<td>
<input type="text" size="10" name="age">
</td>
<td>
性别:
</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<input type="submit" name="submit" value="提交">
</td>
<td>
<input type="reset" name="reset" value="重置">
</td>
</tr>
</table>
</form>
<table width="455" border="0" align="center" bordercolor="#666666">
<tr bgcolor="#0099FF">
<td width="57">
编号:</td>
<td width="74">
姓名:</td>
<td width="94">
性别:</td>
<td width="112">
年龄:</td>
<td width="100">
操作:</td>
</tr>
<%
if(null!=rs){
int i = 0;
while(rs.next())
{
%>
<tr <%if(i%2>0){%>bgcolor="#BDECFD"<%}else{%>bgcolor="#A2DAFF"<%}%>>
<td>
<%out.print(i);%>
</td>
<td>
<%=rs.getString("name"
%>
</td>
<td>
<%=rs.getString("sex"
%>
</td>
<td>
<%=rs.getString("age"
%>
</td>
<td>
<a href="userdelete.jsp?ID=<%=rs.getInt(1)%>">删除</a>
</td>
</tr>
<%
i++;
if(i>=countPageRecord) break; //当前页显示完,则退出
}
}
con.close();
sqlStmt.close();
rs.close();
%>
<tr>
<%
out.print("当前第"+dipage+"页,每页"+countPageRecord+"条记录,"
;
if(dipage==1)//当前是首页
{
out.print("首页,上一页,"
;
}
else//当前不是首页
{
out.print("<a href=userlist.jsp?dipage=1>首页</a>,"
;
out.print("<a href=userlist.jsp?dipage="+(dipage-1)+">上一页</a>,"
;
}
if(dipage==countPage)//当前是末页
{
out.print("下一页,末页"
;
}
else//当前不是末页
{
out.print("<a href=userlist.jsp?dipage="+(dipage+1)+">下一页</a>,"
;
out.print("<a href=userlist.jsp?dipage="+countPage+">末页</a>"
;
}
%>
</tr>
</table>
userinsert.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<%!
/**
* 从8859_1转向GB2312
* @param oldString
* @return
*/
public static String I8859_1ToGB2312(String oldString)
{
try{
oldString = oldString.trim();
return new String(oldString.getBytes("8859_1"
, "GB2312"
;
}
catch(Exception e){
return oldString;
}
}
/**
* 从GB2312转向8859_1
* @param oldString
* @return
*/
public static String IGB2312To8859_1(String oldString){
try{
oldString = oldString.trim();
return new String(oldString.getBytes("GB2312"
, "8859_1"
;
}catch(Exception e){
return oldString;
}
}
%>
<%
String username = I8859_1ToGB2312(request.getParameter("name"
);
String sex = I8859_1ToGB2312(request.getParameter("sex"
);
String age = I8859_1ToGB2312(request.getParameter("age"
);
Connection con;
Statement stmt;
ResultSet rs;
Class.forName("dm4.jdbc.driver.Dm4Driver"
.newInstance();
String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con = DriverManager.getConnection(url,name,password);
int b =-1;
int primaryKey = -1;
stmt = con.createStatement();
String sqlstr = "select max(id) from userinfo";
rs = stmt.executeQuery(sqlstr);
rs.next();
primaryKey = rs.getInt(1);
primaryKey = primaryKey + 1;
String Sql = "insert into userinfo (id,name,sex,age)values("+primaryKey+",'"+username+"','"+sex+"','"+age+"')";
b = stmt.executeUpdate(Sql);
con.close();
stmt.close();
rs.close();
response.sendRedirect("./userlist.jsp"
;
%>
userdelete.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<%
int IDp;
try
{
IDp=Integer.parseInt(request.getParameter("ID"
);
}
catch(Exception e)
{
IDp=0;
}
Connection con;
Statement stmt;
Class.forName("dm4.jdbc.driver.Dm4Driver"
.newInstance();
String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con = DriverManager.getConnection(url,name,password);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String Sql = "delete from userinfo where ID="+IDp;
stmt.executeUpdate(Sql);
con.close();
stmt.close();
response.sendRedirect("./userlist.jsp"
;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<%
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage"

if(pages==null)
{
pages="1";
}
try
{
dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
%>
<%
Connection con;
Class.forName("dm4.jdbc.driver.Dm4Driver"

String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con= DriverManager.getConnection(url,name,password);
Statement sqlStmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sqlQuery="select * from userinfo";
ResultSet rs=sqlStmt.executeQuery(sqlQuery);
rs.beforeFirst();
rs.last();//移动到最后一行的行号
//int rowNumber=rs.getRow();//得到最后一行的行号
int countRecord=0;//记录条数
int countPage=0;//总页数
int countPageRecord=5;//每页3条记录,要设置每页记录条数就更改这个变量的值
countRecord=rs.getRow();//得到总页数
if(countRecord/countPageRecord==0)
countPage=countRecord/countPageRecord;
else
countPage=countRecord/countPageRecord+1;
//把记录指针移至当前页第一条记录之前
if((dipage-1)*countPageRecord==0)
rs.beforeFirst();
else
rs.absolute((dipage-1)*countPageRecord);
%>
<form action="userinsert.jsp" method="post" name="form1">
<table align="center">
<tr>
<td>
姓名:
</td>
<td>
<input type="text" size="10" name="name">
</td>
<td>
年龄:
</td>
<td>
<input type="text" size="10" name="age">
</td>
<td>
性别:
</td>
<td>
<select name="sex">
<option value="男">男</option>
<option value="女">女</option>
</select>
</td>
</tr>
</table>
<table align="center">
<tr>
<td>
<input type="submit" name="submit" value="提交">
</td>
<td>
<input type="reset" name="reset" value="重置">
</td>
</tr>
</table>
</form>
<table width="455" border="0" align="center" bordercolor="#666666">
<tr bgcolor="#0099FF">
<td width="57">
编号:</td>
<td width="74">
姓名:</td>
<td width="94">
性别:</td>
<td width="112">
年龄:</td>
<td width="100">
操作:</td>
</tr>
<%
if(null!=rs){
int i = 0;
while(rs.next())
{
%>
<tr <%if(i%2>0){%>bgcolor="#BDECFD"<%}else{%>bgcolor="#A2DAFF"<%}%>>
<td>
<%out.print(i);%>
</td>
<td>
<%=rs.getString("name"

</td>
<td>
<%=rs.getString("sex"

</td>
<td>
<%=rs.getString("age"

</td>
<td>
<a href="userdelete.jsp?ID=<%=rs.getInt(1)%>">删除</a>
</td>
</tr>
<%
i++;
if(i>=countPageRecord) break; //当前页显示完,则退出
}
}
con.close();
sqlStmt.close();
rs.close();
%>
<tr>
<%
out.print("当前第"+dipage+"页,每页"+countPageRecord+"条记录,"

if(dipage==1)//当前是首页
{
out.print("首页,上一页,"

}
else//当前不是首页
{
out.print("<a href=userlist.jsp?dipage=1>首页</a>,"

out.print("<a href=userlist.jsp?dipage="+(dipage-1)+">上一页</a>,"

}
if(dipage==countPage)//当前是末页
{
out.print("下一页,末页"

}
else//当前不是末页
{
out.print("<a href=userlist.jsp?dipage="+(dipage+1)+">下一页</a>,"

out.print("<a href=userlist.jsp?dipage="+countPage+">末页</a>"

}
%>
</tr>
</table>
userinsert.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<%!
/**
* 从8859_1转向GB2312
* @param oldString
* @return
*/
public static String I8859_1ToGB2312(String oldString)
{
try{
oldString = oldString.trim();
return new String(oldString.getBytes("8859_1"


}
catch(Exception e){
return oldString;
}
}
/**
* 从GB2312转向8859_1
* @param oldString
* @return
*/
public static String IGB2312To8859_1(String oldString){
try{
oldString = oldString.trim();
return new String(oldString.getBytes("GB2312"


}catch(Exception e){
return oldString;
}
}
%>
<%
String username = I8859_1ToGB2312(request.getParameter("name"

String sex = I8859_1ToGB2312(request.getParameter("sex"

String age = I8859_1ToGB2312(request.getParameter("age"

Connection con;
Statement stmt;
ResultSet rs;
Class.forName("dm4.jdbc.driver.Dm4Driver"

String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con = DriverManager.getConnection(url,name,password);
int b =-1;
int primaryKey = -1;
stmt = con.createStatement();
String sqlstr = "select max(id) from userinfo";
rs = stmt.executeQuery(sqlstr);
rs.next();
primaryKey = rs.getInt(1);
primaryKey = primaryKey + 1;
String Sql = "insert into userinfo (id,name,sex,age)values("+primaryKey+",'"+username+"','"+sex+"','"+age+"')";
b = stmt.executeUpdate(Sql);
con.close();
stmt.close();
rs.close();
response.sendRedirect("./userlist.jsp"

%>
userdelete.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.sql.*"%>
<%
int IDp;
try
{
IDp=Integer.parseInt(request.getParameter("ID"

}
catch(Exception e)
{
IDp=0;
}
Connection con;
Statement stmt;
Class.forName("dm4.jdbc.driver.Dm4Driver"

String url = "jdbc:dm4://127.0.0.1:12345/test";
String name = "SYSDBA";
String password = "SYSDBA";
con = DriverManager.getConnection(url,name,password);
stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String Sql = "delete from userinfo where ID="+IDp;
stmt.executeUpdate(Sql);
con.close();
stmt.close();
response.sendRedirect("./userlist.jsp"

%>