<br />我刚接触JSP,试着连接数据库,但去总出错,请大家指教<br /><br /><table border="0" align="left" class=ppc_download_ad_frame cellspacing=0 cellpadding=0 width="1%" style="margin-top:10px;margin-right:7px;margin-bottom:3px;margin-left:0px">
<tr>
<td id=a><img height=9 width=9></td>
<td id=b width="100%"><img height=1 width=1></td>
<td id=c><img height=9 width=9></td>
</tr>
<tr>
<td id=d><img height=1 width=1></td>
<td id=e valign=top height="100%"><!-- frame contents -->
<table cellspacing=0 cellpadding=0 border=0>
<tr>
<td><div id="w_hzh"></div></td>
</tr>
</table>
<!-- /frame contents --></td>
<td id=f><img height=1 width=1></td>
</tr>
<tr>
<td id=g><img height=9 width=9></td>
<td id=h><img height=1 width=1></td>
<td id=i><img height=9 width=9></td>
</tr>
</table><%@ page contentType="text/HTML;charset=gb2312"%> <%@ page import="java.sql.*"%> <HTML> <body> <%Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver" );String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=iwork2;User=sa;Password=sa";//class是我的数据库名,你可作相应修改Connection conn= DriverManager.getConnection( url );Statement stmt=conn.createStatement(); String sql="select * from bo_fw"; ResultSet rs=stmt.executeQuery(sql); while(rs.next()) {%> 您的第一个字段内容为:<%=rs.getString(wh)%> 您的第二个字段内容为:<%=rs.getString(rq)%> <%}%> <%out.print("数据库操作成功,恭喜你");%> <%rs.close(); stmt.close(); conn.close(); %> </body> </HTML>
</div>
</div>