MyEclipse------如何查询MySQL数据库里面表的信息
2016-03-24 20:07
405 查看
testExecuteQuary.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <%@page import="java.sql.*" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'testExecuteQuery.jsp' starting page</title> </head> <body> <% //student为数据库的名字 String url="jdbc:mysql://localhost:3306/student?useSSL=true"; String useName="root"; String password="2277092"; String sql=null; Connection conn=null; Statement stmt=null; //加载驱动类 try{ Class.forName("com.mysql.jdbc.Driver"); out.print("加载驱动类成功"); } catch(ClassNotFoundException e){ out.print("加载驱动类时出现异常"); } try{ conn=DriverManager.getConnection(url,useName,password); stmt=conn.createStatement(); sql="select * from info";//info为表名 ResultSet rs=stmt.executeQuery(sql); %> <center> <table border="1" width="270" cellspacing="0" cellpadding="0"> <tr> <td width=50 align="center" valign="middle">学号</td> <td width="80" align="center">姓名</td> <td width=140 align="center">电话</td> </tr> <% while(rs.next()){ int id=rs.getInt(1); String name=rs.getString(2); String phone=rs.getString(3); %> <tr> <td height="40" align="center" valign="middle"><%=id %></td> <td align="center" valign="middle"><%=name %></td> <td align="center" valign="middle"><%=phone %></td> </tr> <% } rs.close(); stmt.close(); %> </table> </center> <% } catch(SQLException e){ out.print("出现SQLException异常"); } finally{ try{ if(conn!=null){ conn.close(); } } catch(SQLException e){ out.print("关闭数据库连接时出现异常"); } } %> </body> </html>
相关文章推荐
- Spring Batch 之 Sample(Hello World)(三)
- Spring Batch 之 Spring Batch 简介(一)
- MyEclipse------如何连接MySQL
- Struts2中的相对路径与绝对路径
- MyEclipse------从服务器下载文件
- java中利用jxl包对Excel文件进行修改保存
- eclipse安装svn
- Spring DI模式 小样例
- spring+mybatis使用事务管理不生效原因分析
- activiti自定义流程之Spring整合activiti-modeler5.16实例(二):创建流程模型
- activiti自定义流程之Spring整合activiti-modeler5.16实例(二):创建流程模型
- Spring开发-spring入门
- Java 华为推送 Access Token过期刷新
- java回顾篇——进制转换,变量,数据类型的转换,运算符
- java7自动资源管理
- JAVA的POI操作Excel
- bug_ _java.lang.RuntimeException: Unable to start activity ComponentInfo{包名/类名}
- java并发:线程同步机制之Lock
- 【JAVA】导出jar包时,Class files on classpath not found
- java Collection概述