zoukankan      html  css  js  c++  java
  • 原生JDBC的使用

    public class ConnDB {
        private Connection ct = null;
       //驱动程序名
        String driver = "com.mysql.jdbc.Driver";
        // URL指向要访问的数据库名scutcs
        String url = "jdbc:mysql://127.0.0.1:3306/develop";
        // MySQL配置时的用户名
        String user = "root";
        // Java连接MySQL配置时的密码
        String password = "wzy123";
    
        public static Connection getConn(){
            try{
                Class.forName(driver);    
                ct = DriverManager.getConnection(url, user, password);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return ct;
        }
    
        public int add(String day,String time,
                    String volname,String volclass,String voltel,String volemail){
                Connection con = DbConnect.this.getConn();
                int num = -1;
                
                try {
                    java.sql.Statement statement = con.createStatement();
                     num = statement.executeUpdate( "insert into tb_volinfo(day,time,volname,volclass,voltel,volemail) "
                            + "values('"+day+"','"+time+"','"+volname+"','"+volclass+"','"+voltel+"','"+volemail+"')");
                
                    if(statement!=null){
                        statement.close();
                    }
                    if(con!=null){
                        con.close();//关闭数据库连接
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
    
                return num;
            }
            public boolean SelectVal(String volname,String voltel){
                Connection con1 = DbConnect.this.getConn();
                ResultSet result =null;
                
                try {
                    java.sql.Statement statement = con1.createStatement();
                    result = statement.executeQuery("select * from tb_volinfo where volname='"+volname+"' and voltel='"+voltel+"';");
                    while(result.next()){
                        return true;
                    }
                    if(statement!=null){
                        statement.close();
                    }
                    if(con1!=null){
                        con1.close();//关闭数据库连接
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return false;
            }
    }
  • 相关阅读:
    点击图片等比缩放
    C# 使用 NPOI 库读写 Excel 文件
    vue url生产二维码
    centos Linux 同步Windows 时间
    centos 搭建 docker sentry
    centos 安装 pip
    webpack 提升90%的构建速度 HardSourceWebpackPlugin
    webpack 原生分析
    webpack 分析
    nodejs——js 实现webSocket 兼容移动端
  • 原文地址:https://www.cnblogs.com/wwzyy/p/8686876.html
Copyright © 2011-2022 走看看