原代码如下:
<%@page contentType="text/html;charset=GB2312"%>
<%@ page import="myproject.ISOtoGB2312"%>
<html>
<head>
<title>executeQuery</title>
</head>
<body bgcolor="#ffffff">
<%
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=lab";
String userName="fhy";
String password="428";
String sql=null;
Connection conn=null;
Statement stmt=null;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e){
out.println("加载驱动器类时出现异常");
}
try{
conn=DriverManager.getConnection(url,userName,password);
stmt=conn.createStatement();
sql="select *from student";
ResultSet rs=stmt.executeQuery(sql);
%>
<font color="#333333"><b>查询到的信息如下:</b></font>
<table width="67%" border="1" align="center" cellspacing="0" borde-rcolor="#333333" bgcolor="#FFFFFF">
<tr bgcolor="#69B4D8">
<td><dir align="center">学号</dir></td>
<td><div align="center"><b>姓名</b></div></td>
<td><dir align="center"><b>性别</b></dir></td>
<td><div align="center"><b>班级</b></div></td>
</tr>
<%
while(rs.next())
{
%>
<tr bgcolor="#FFB895">
<td><div align="center"><%=rs.getString(1)%></div></td>
<td><dir align="center"><%=rs.getString(2)%></dir></td>
<td><dir align="center"><%=rs.getString(3)%></dir></td>
<td><div align="center"><%=rs.getString(4)%></div></td>
</tr>
<% } %>
</table>
<% rs.close();
stmt.close();
}catch(SQLException e){
System.out.println("出现SQLException异常");
}finally{
try{
if(conn !=null)conn.close();
}catch(SQLException e){
System.out.println("关闭数据库连接时出现异常");
}
}
%>
</body>
</html>
编译时错误如下提示:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
Compiling 1 source file to E:\myweb\Labser\build\generated\classes
E:\myweb\Labser\build\generated\src\org\apache\jsp\Confirmation_jsp.java:61: 警告:编码 GBK 的不可映射字符
out.println("鍔犺浇椹卞姩鍣ㄧ被鏃跺嚭鐜板紓甯?);
^
E:\myweb\Labser\build\generated\src\org\apache\jsp\Confirmation_jsp.java:70: 警告:编码 GBK 的不可映射字符
out.write(" <font color=\"#333333\"><b>鏌ヨ?鍒扮殑淇℃伅濡備笅锛?/b></font>\n");
^
E:\myweb\Labser\build\generated\src\org\apache\jsp\Confirmation_jsp.java:61: 未结束的字符串字面值
out.println("鍔犺浇椹卞姩鍣ㄧ被鏃跺嚭鐜板紓甯?);
^
1 错误
2 警告
E:\myweb\Labser\nbproject\build-impl.xml:364: The following error occurred while executing this line:
E:\myweb\Labser\nbproject\build-impl.xml:149: Compile failed; see the compiler error output for details.
生成失败(总时间:3 秒)