【JSP开源代码栏目提醒】:网学会员--在 JSP开源代码编辑为广大网友搜集整理了:excel.jsp绩等信息,祝愿广大网友取得需要的信息,参考学习。
<%@page contentType="text/html;charset=gbk"%>
<%@page import="java.sql.*"%>
<%!
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
%>
<%
//安装驱动程序--
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce)
{
out.println(ce.getMessage());
}
//执行--
try
{
//非数据源虚拟路径连接法
String str="jdbc:odbc:driver={microsoft excel driver (*.xls)};dbq=";
str+=application.getRealPath("WEB-INF/excel.xls");
//非数据源连接法
conn=DriverManager.getConnection(str,"","");
stmt=conn.createStatement();
rs=stmt.executeQuery("SELECT * FROM [Sheet1$]");
out.print("<table border=1 bordercolor=red>");
while(rs.next())
{
out.print("<tr>");
out.print("<td><b>"+rs.getString("id")+"</b></td>");
out.print("<td>"+rs.getString("name")+"</td>");
out.print("<td>"+rs.getString("sex")+"</td>");
out.print("<td>"+rs.getString("age")+"</td>");
out.print("</tr>");
}
out.print("</table>");
}
catch(SQLException e)
{
out.println(e.getMessage());
}
finally
{
if(rs!=null)
{
try
{
rs.close();
}
catch(SQLException ee)
{
out.println(ee.getMessage());
}
}
if(stmt!=null)
{
try
{
stmt.close();
}
catch(SQLException ee)
{
out.println(ee.getMessage());
}
}
if(conn!=null)
{
try
{
conn.close();
}
catch(SQLException ee)
{
out.println(ee.getMessage());
}
}
}
%>
上一篇:
examTest.jsp
下一篇:
网络能耗监测系统管理端的研究与实现