zoukankan      html  css  js  c++  java
  • 用一个jsp实现对数据库发访问

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <%@ page contentType="text/html; charset=gb2312" %>   
    <%@ page language="java" %>   
    <%@ page import="com.mysql.jdbc.Driver" %>   
    <%@ page import="java.sql.*" %>   
    <%   
    //驱动程序名   
    String driverName="com.mysql.jdbc.Driver";   
    //数据库用户名   
    String userName="root";   
    //密码   
    String userPasswd="123";   
    //数据库名   
    String dbName="zzga";   
    //表名   
    String tableName="t_device";   
    //联结字符串   
    String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;   
    Class.forName("com.mysql.jdbc.Driver").newInstance();   
    Connection connection=DriverManager.getConnection(url);   
    Statement statement = connection.createStatement();   
    String sql="SELECT * FROM "+tableName;   
    ResultSet rs = statement.executeQuery(sql);   
    //获得数据结果集合   
    ResultSetMetaData rmeta = rs.getMetaData();   
    //确定数据集的列数,亦字段数   
    int numColumns=rmeta.getColumnCount();   
    out.print(" 精度 &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp&nbsp &nbsp");
    out.print("纬度&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp&nbsp &nbsp");
    out.print("  地址 ");
    out.print("<br>");
    // 输出每一个数据值     
    while(rs.next()) {

    out.print(rs.getString(4)+" ");

    out.print("|");

    out.print(rs.getString(5));
    out.print("|");

    out.print(rs.getString(3));

    out.print("<br>");

    }  
    out.print("数据库操作成功,恭喜你");   
    rs.close();   
    statement.close();   
    connection.close();   
    %>
    </html>

  • 相关阅读:
    OKHttp使用详解
    spring okhttp3
    HTTPS SSL/TLS协议
    springboot @scheduled 并发
    spring @Scheduled 并发
    CORSFilter 跨域资源访问
    定时任务 spring @Scheduled注解
    spring proxy-target-class
    iOS 适用于Pad上的菜单弹出界面-最简单的一种实现记录
    Mac系统清理、占用空间大、空间不够、查看系统文件大小分布
  • 原文地址:https://www.cnblogs.com/zzyrunning/p/4598137.html
Copyright © 2011-2022 走看看