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;
            }
    }
  • 相关阅读:
    实验6.1
    SOA
    python的镜像包安装
    中文分词:双向匹配最大算法(BI-MM)
    从github中获取代码
    解决文件冲突
    创建分支
    上传本地文件到github
    mysql事务
    查询练习2
  • 原文地址:https://www.cnblogs.com/wwzyy/p/8686876.html
Copyright © 2011-2022 走看看