求JSP连接数据库代码 rt 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.d8net.cn/read.php?tid=16837这里连接代码比较齐全。 <%@ page contentType="text/html;charset=GB2312" %><%@ page import="java.sql.*" %><%int dipage=1;//当前页码数默认为1String pages=request.getParameter("dipage");if(pages==null){ pages="1";}try{ dipage=Integer.parseInt(pages);}catch(Exception e){ dipage=1; }%><HTML><head><title>用户数据</title><link href="mystyle.css" rel="stylesheet" type="text/css"></head><BODY><center> <% Connection con; Statement sql; ResultSet rs; try { Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver"); } catch(ClassNotFoundException e) { out.print("类找不到!"); }// try// {// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序// }// catch(ClassNotFoundException e)// {// out.print("类找不到!");// } try { con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs","sa",""); sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);// con=DriverManager.getConnection("jdbc:odbc:pubs","sa","");// sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);// sql.setMaxRows(10);//控制输出记录最大数量为10 rs=sql.executeQuery("SELECT * FROM titles"); int countRecord=0;//记录条数 int countPageRecord=0;//每页记录条数 int countPage=0;//总页数 countPageRecord=5;//每页5条记录,要设置每页记录条数就更改这个变量的值 //得到记录的条数 rs.last(); countRecord=rs.getRow();// out.print(countRecord); //得到总页数 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); out.print("<Table Border style='font-size: 10pt'>"); out.print("<TR><td colspan=10 align=center><strong>用户数据</strong></td></tr>"); out.print("<TR>"); out.print("<Td nowrap>"+"title_id"); out.print("<Td nowrap>"+"title"); out.print("<Td nowrap>"+"type"); out.print("<Td nowrap>"+"pub_id"); out.print("<Td nowrap>"+"price"); out.print("<Td nowrap>"+"advance"); out.print("<Td nowrap>"+"royalty"); out.print("<Td nowrap>"+"ytd_sales");// out.print("<Td nowrap>"+"notes"); out.print("<Td nowrap>"+"pubdate"); out.print("</TR>"); int i=0; while(rs.next()) { out.print("<TR>"); out.print("<TD nowrap>"+rs.getString("title_id")+"</TD>"); out.print("<TD nowrap>"+rs.getString("title")+"</TD>"); out.print("<TD nowrap>"+rs.getString("type")+"</TD>"); out.print("<TD nowrap>"+rs.getString("pub_id")+"</TD>"); out.print("<TD nowrap>"+rs.getFloat("price")+"</TD>"); out.print("<TD nowrap>"+rs.getLong("advance")+"</TD>"); out.print("<TD nowrap>"+rs.getInt("royalty")+"</TD>"); out.print("<TD nowrap>"+rs.getInt("ytd_sales")+"</TD>");// out.print("<TD nowrap>"+rs.getString("notes")+"</TD>"); out.print("<TD nowrap>"+rs.getString("pubdate")+"</TD>"); out.print("</TR>") ; i++; if(i>=countPageRecord) break; //当前页显示完,则退出循环 } out.print("<TR><td colspan=10 align=center>"); out.print("共"+countRecord+"条记录,共"+countPage+"页,当前第"+dipage+"页,每页"+countPageRecord+"条记录,"); if(dipage==1)//当前是首页 ; else//当前不是首页 { out.print("<a href=userPage1.jsp?dipage=1>首页</a>,"); out.print("<a href=userPage1.jsp?dipage="+(dipage-1)+">上一页</a>,"); } if(dipage==countPage)//当前是末页 ; else//当前不是末页 { out.print("<a href=userPage1.jsp?dipage="+(dipage+1)+">下一页</a>,"); out.print("<a href=userPage1.jsp?dipage="+countPage+">末页</a>"); } out.print("</td></tr>"); out.print("</Table>"); con.close(); } catch(SQLException e1) { out.print(e1+"<br>"); out.print("SQL异常!"); } %> </center></BODY></HTML> 问下有没有谁有邮件编辑器的html代码呀~ 求助关于使用Jquery进行注册 关于菜单的问题 剛學JDBC, 遇上問題了 在JS中怎么往图片上添加文字 jsp 怎样上传文件 求源代码代码 高分请教:如何用jsp实现在网页中排版编辑(如:http://www.beidou7.com/liudong/edit/example/test.asp) 100分求javabean,连接mysql的 一个性能的问题 那一位有邮件系统的源代码(1000分送) 诚邀长三角地区一起网络创业的朋友(熟悉JSP,JAVA) 如何实现URL重写?
这里连接代码比较齐全。
<%@ page import="java.sql.*" %>
<%
int dipage=1;//当前页码数默认为1
String pages=request.getParameter("dipage");
if(pages==null)
{
pages="1";
}
try
{
dipage=Integer.parseInt(pages);
}
catch(Exception e)
{
dipage=1;
}
%>
<HTML>
<head>
<title>用户数据</title>
<link href="mystyle.css" rel="stylesheet" type="text/css">
</head>
<BODY>
<center>
<% Connection con;
Statement sql;
ResultSet rs;
try
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e)
{
out.print("类找不到!");
}
// try
// {
// Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//加载驱动程序
// }
// catch(ClassNotFoundException e)
// {
// out.print("类找不到!");
// }
try
{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs","sa","");
sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
// con=DriverManager.getConnection("jdbc:odbc:pubs","sa","");
// sql=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
// sql.setMaxRows(10);//控制输出记录最大数量为10
rs=sql.executeQuery("SELECT * FROM titles");
int countRecord=0;//记录条数
int countPageRecord=0;//每页记录条数
int countPage=0;//总页数
countPageRecord=5;//每页5条记录,要设置每页记录条数就更改这个变量的值
//得到记录的条数
rs.last();
countRecord=rs.getRow();
// out.print(countRecord);
//得到总页数
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);
out.print("<Table Border style='font-size: 10pt'>");
out.print("<TR><td colspan=10 align=center><strong>用户数据</strong></td></tr>");
out.print("<TR>");
out.print("<Td nowrap>"+"title_id");
out.print("<Td nowrap>"+"title");
out.print("<Td nowrap>"+"type");
out.print("<Td nowrap>"+"pub_id");
out.print("<Td nowrap>"+"price");
out.print("<Td nowrap>"+"advance");
out.print("<Td nowrap>"+"royalty");
out.print("<Td nowrap>"+"ytd_sales");
// out.print("<Td nowrap>"+"notes");
out.print("<Td nowrap>"+"pubdate");
out.print("</TR>");
int i=0;
while(rs.next())
{ out.print("<TR>");
out.print("<TD nowrap>"+rs.getString("title_id")+"</TD>");
out.print("<TD nowrap>"+rs.getString("title")+"</TD>");
out.print("<TD nowrap>"+rs.getString("type")+"</TD>");
out.print("<TD nowrap>"+rs.getString("pub_id")+"</TD>");
out.print("<TD nowrap>"+rs.getFloat("price")+"</TD>");
out.print("<TD nowrap>"+rs.getLong("advance")+"</TD>");
out.print("<TD nowrap>"+rs.getInt("royalty")+"</TD>");
out.print("<TD nowrap>"+rs.getInt("ytd_sales")+"</TD>");
// out.print("<TD nowrap>"+rs.getString("notes")+"</TD>");
out.print("<TD nowrap>"+rs.getString("pubdate")+"</TD>");
out.print("</TR>") ;
i++;
if(i>=countPageRecord) break; //当前页显示完,则退出循环
}
out.print("<TR><td colspan=10 align=center>");
out.print("共"+countRecord+"条记录,共"+countPage+"页,当前第"+dipage+"页,每页"+countPageRecord+"条记录,");
if(dipage==1)//当前是首页
;
else//当前不是首页
{
out.print("<a href=userPage1.jsp?dipage=1>首页</a>,");
out.print("<a href=userPage1.jsp?dipage="+(dipage-1)+">上一页</a>,");
}
if(dipage==countPage)//当前是末页
;
else//当前不是末页
{
out.print("<a href=userPage1.jsp?dipage="+(dipage+1)+">下一页</a>,");
out.print("<a href=userPage1.jsp?dipage="+countPage+">末页</a>");
}
out.print("</td></tr>");
out.print("</Table>");
con.close();
}
catch(SQLException e1)
{
out.print(e1+"<br>");
out.print("SQL异常!");
}
%>
</center>
</BODY>
</HTML>