首页 > 其他分享 >web实验3

web实验3

时间:2024-06-19 21:36:16浏览次数:13  
标签:web String System private 实验 stmt println out

三、实验步骤

1)    打开MySQL,新建一个数据库。

2)    新建一个数据库表。

3)    在表中增加若干记录,作为初始数据。

4)    打开Eclipse软件,新建一个名为Lab04的Web项目,并设置其部署程序为Tomcat。

5)    在Lab04中添加文件,编写代码。

6)    DBBean. java文件代码

package book.bean;



import java.sql.*;




public class DBBean {

    private String driverStr = "com.mysql.jdbc.Driver";

    private String connStr = "jdbc:mysql://localhost:3306/students?useSSL=false&useUnicode=true&characterEncoding=utf-8";

    private String dbusername = "root";

    private String dbpassword = "123456";

    private Connection conn = null;

    private Statement stmt = null;



    public DBBean() {

        try {

            Class.forName(driverStr);

            conn = DriverManager.getConnection(connStr, dbusername, dbpassword);

            stmt = conn.createStatement();

            System.out.println("连接成功");

        } catch (Exception ex) {

            System.out.println("数据库连接失败!");

        }

    }



    /**

     * 执行更新操作

     * @param s

     * SQL语句

     * @return

     * 更新操作的结果

     */

   
public int executeUpdate(String s) {

        int result = 0;

        try {

            stmt = conn.createStatement();

            result = stmt.executeUpdate(s);



            System.out.println("看看是不是执行了");



        } catch (SQLException ex) {

            ex.printStackTrace();

            System.out.println("更新出现异常!");

        }

        return result;

    }



    /**

     * 执行查询操作

     * @param s

     * SQL语句

     * @return

     * 查询结果

     */

   
public ResultSet executeQuery(String s) {

        ResultSet rs = null;

        try {

            rs = stmt.executeQuery(s);



        } catch (Exception ex) {

            System.out.println("查询出现异常!");

        }

        return rs;

    }



    /**

     * 关闭数据库

     */

   
public void close() {

        try {

            stmt.close();

            conn.close();

        } catch (Exception e) {

        }

    }

标签:web,String,System,private,实验,stmt,println,out
From: https://www.cnblogs.com/bdsz/p/18257447

相关文章

  • 数据库实验1
    掌握使用SQL语言进行各种查询的操作和视图的操纵方法。二、实验要求:在现有的数据库上进行各种查询操作,对视图的创建、使用等操作。三、实验步骤:1、开始→程序→MicrosoftSQLServer→SQLServerManagementStudio。2、在“连接到服务器”对话框中,选择“Windows身份验......
  • web实验1
    1)编写index.jsp文件,展示某一类物品或知识的介绍,可以是歌曲、人物、名胜古迹等。要求至少有三个条目,用户登录后才能浏览这三个条目的内容。如果用户尚未登录,需要显示用户为“游客”,否则显示用户名。页面下端设置超链接,指向login.jsp。如果用户尚未登录,单击了某一条目的内容,则系统......
  • web实验2
    <%@pagecontentType="text/html;charset=UTF-8"language="java"%><html><head>   <title>无题</title></head><bodybackground="/image/gb1.jpg"><divalign="center"style......
  • Linux 中断实验
    Linux中断实验先来回顾一下裸机实验里面中断的处理方法:①、使能中断,初始化相应的寄存器。②、注册中断服务函数,也就是向irqTable数组的指定标号处写入中断服务函数②、中断发生以后进入IRQ中断服务函数,在IRQ中断服务函数在数组irqTable里面查找具体的中断处理函数,找......
  • verilog 设计与综合实验报告(5)
    题目5:序列检测器1、设计方案2、程序代码modulesequential5_detector(inputi_clk, inputi_rst, inputi_seq, outputregout);parameteridle=5'b00000,s1=5'b00001,s2=5'b00010,s3=5'b00100,......
  • 【云服务器介绍】选择指南 腾讯云 阿里云全配置对比 搭建web 个人开发 app 游戏服务器
    ​省流目录:适用于博客建站(2-4G)、个人开发/小型游戏[传奇/我的世界/饥荒](4-8G)、数据分析/大型游戏[幻兽帕鲁/雾锁王国]服务器(16-64G)1.京东云-618专属活动 官方采购季专属活动地址:京东云-618采购季服务器活动专区https://3.cn/20-J4jjX京东云又双叒降价了!活动页大改,增加两......
  • Javaweb
    所花时间: 0.5h代码量(行): 50左右搏客量(篇): 1了解到的知识点:Javaweb备注(其他): 表单标签里面post和get的区别 在刚接触到jsp文件时,我对于里面提交数据的表单标签里面的post和get有点分不清楚<formaction="deletejudge.jsp"metho......
  • 对 websocket 进行封装 (心跳检测 断开重连 发送事件等等 支持断开重连后发送上次发
    代码封装:  //websocketService.jsimport{ref}from"vue";const{DEV,VITE_APP_PUSH_WS}=import.meta.env;const{push_ws}=window.WEB_CONFIG;constbaseWsUrl=DEV?VITE_APP_PUSH_WS:push_ws;classWebSocketService{constructor(ur......
  • webp格式的动图怎么转换成jpeg图片?
    有没有自媒体小伙伴遇到这样的问题呢?找到一张好看的webp格式的图片素材,但是编辑软件却无法打开,显示不支持webp格式的图片。遇到这种情况,你是选择放弃这张素材,重新寻找呢?其实完全没有必要!只要将格式转换成jpeg,就可以继续编辑图片了。方法一:使用图片在线转换工具有很多在线转换工......
  • Spring WebSocket中关于WebSocket配置类的注意事项
    情况1:如果只需要进行简单的通信,不需要消息代理和STOMP协议支持,那么只需要实现WebSocketConfigurer接口注意:实现的接口是WebSocketConfigurer,使用的注解是@EnableWebSocketimportorg.springframework.context.annotation.Configuration;importorg.springframework.web.socke......