📄 dbjsp_0002ejsp_jsp.java
字号:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;
public class dbJsp_0002ejsp_jsp extends HttpJspBase {
static {
}
public dbJsp_0002ejsp_jsp( ) {
}
private static boolean _jspx_inited = false;
public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=GBK");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/dbJsp.jsp";from=(0,48);to=(2,0)]
out.write("\r\n<html>\r\n");
// end
// HTML // begin [file="/dbJsp.jsp";from=(2,46);to=(4,0)]
out.write("\r\n<head>\r\n");
// end
// begin [file="/dbJsp.jsp";from=(4,2);to=(6,0)]
String tableName = request.getParameter("tableName"); //获取用户要显示数据的表名
// end
// HTML // begin [file="/dbJsp.jsp";from=(6,2);to=(7,7)]
out.write("\r\n<title>");
// end
// begin [file="/dbJsp.jsp";from=(7,10);to=(7,19)]
out.print(tableName);
// end
// HTML // begin [file="/dbJsp.jsp";from=(7,21);to=(10,0)]
out.write("表中数据</title>\r\n</head>\r\n<body bgcolor=\"#FFFFFF\" text=\"#000000\">\r\n");
// end
// begin [file="/dbJsp.jsp";from=(10,2);to=(82,0)]
Connection connection = null; //定义与数据库进行连接的Connection对象
ResultSet rs = null; //定义数据库查询的结果集
Statement statement = null; //定义查询数据库的Statement对象
if (tableName.equals("studentbase"))
{
out.println("<h2 align=center>学生基本信息表中的数据</h2>");
}
else if (tableName.equals("studentaddress"))
{
out.println("<h2 align=center>学生地址表中的数据</h2>");
}
else
{
out.println("<h2 align=center>选课信息表中的数据</h2>");
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); //指定与数据库连接使用JDBC-ODBC桥驱动程序
String url = "jdbc:odbc:student"; //指定数据源名
connection = DriverManager.getConnection(url); //与数据源建立连接
statement = connection.createStatement(); //创建Statement接口实例
String sql = "select * from " + tableName; //创建取出用户指定表中所有数据的SQL语句
rs = statement.executeQuery(sql); //将数据存入结果集中
ResultSetMetaData rsData = rs.getMetaData(); //获取结果集信息
out.println("<table width=75% border=1 align=center><tr>");
for(int i=1; i<=rsData.getColumnCount(); i++) //输出字段名
{
out.println("<td>" + rsData.getColumnLabel(i) + "</td>");
}
out.println("</tr>");
while(rs.next()) //输出表中数据
{
out.println("<tr>");
for(int i=1; i<=rsData.getColumnCount();i++)
{
out.println("<td>" + rs.getString(i) + "</td>");
}
out.println("</tr>");
}
out.println("</table>");
}
catch(SQLException ex){ //捕捉异常
System.out.println("\nERROR:----- SQLException -----\n");
while (ex != null) {
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
ex = ex.getNextException();
}
}
catch(Exception ex ) {
ex.printStackTrace();
}
finally {
try {
if(statement != null)
{
statement.close(); //关闭Statement接口实例
}
if(connection != null)
{
connection.close(); //关闭Connection接口实例
}
}
catch (SQLException ex) {
System.out.println("\nERROR:----- SQLException -----\n");
System.out.println("Message: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("ErrorCode: " + ex.getErrorCode());
}
}
// end
// HTML // begin [file="/dbJsp.jsp";from=(82,2);to=(85,0)]
out.write("\r\n</table></body>\r\n</html>\r\n");
// end
} catch (Throwable t) {
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -