*/ 出自: 编程中国 http://www.bc-cn.net
*/ 作者: tiantiaqn?
*/ 时间: 2007-7-3 编程论坛首发
*/ 声明: 尊重作者劳动,转载请保留本段文字
*/ --------------------------------------------------------------------------------------
问大家,jsp与access的连接需要设置数据源不?
我的程序代码是:
<%@page contentType="text/html;charset=GB2312"%>
<%@page import="java.sql.*"%>
<html>
<body>
<%
Connection con;
Statement sql;
ResultSet rs;
String str="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\tushu1.mdb";
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try
{
con=DriverManager.getConnection(str,"","");
sql=con.createStatement();
rs=sql.executeQuery("Select * From tushu1");
out.print("<Table Border>");
out.print("<TR>");
out.print("<TH width=100>"+"编号");
out.print("<TH width=100>"+"图书名");
out.print("<TH width=100>"+"作者");
out.print("<TH width=100>"+"出版社名");
out.print("<TH width=100>"+"类别");
out.print("<TH width=100>"+"图片");
out.print("</TR>");
while(rs.next())
{
out.print("<TR>");
out.print("<TD>"+rs.getInt(1)+"</TD>");
out.print("<TD>"+rs.getString("图书名")+"</TD>");
out.print("<TD>"+rs.getString("作者")+"</TD>");
out.print("<TD>"+rs.getString("出版社名")+"</TD>");
out.print("<TD>"+rs.getString("类别")+"</TD>");
out.print("<TD>"+rs.getString("图片")+"</TD>");
out.print("</TR>");
}
out.print("</Table>");
con.close();
}
catch(SQLException e1){}
%>
</body>
</html>
怎么读不出表tushu1中的数据呀?先谢谢大家咯