• DriverManager不通过框架链接数据库


        public List<SalesRegisterConfig> getSalesRegisterConfigList()
        {
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            List<SalesRegisterConfig> resultList = new ArrayList<>();
            try{
                 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
                 String linkCloudSql = ConfigUtil.pro.get("linkCloudSql").toString();//数据库IP地址
                 String linkCloudUsername =ConfigUtil.pro.get("linkCloudUsername").toString();//数据库用户名
                 String linkCloudPassword =ConfigUtil.pro.get("linkCloudPassword").toString();//数据库密码
                 
                 conn = DriverManager
                         .getConnection(
                                 linkCloudSql,linkCloudUsername, linkCloudPassword);
                 stmt = conn.createStatement();
                 rs = stmt.executeQuery("select vin,* from SalesRegisterConfig where vin is not null and len(vin)=7");
                 while(rs.next())
                 {
                     SalesRegisterConfig config = new SalesRegisterConfig();
                     config.setId(rs.getInt("ID"));
                     config.setCarserialsid(rs.getString("carSerialsID"));
                     config.setCartypeid(rs.getString("carTypeID"));
                     config.setVin(rs.getString("vin"));
                     resultList.add(config);
                 }
            }
             catch (Exception e) {
                e.printStackTrace();
            } finally {
                 try {
                        if (!conn.isClosed()) {
                            conn.close();
                        }
                        if (!stmt.isClosed()) {
                            stmt.close();
                        }
                        if (!rs.isClosed()) {
                            rs.close();
                        }
                    } catch (SQLException e) {
                        e.printStackTrace();
                    }
            }
             return resultList;
        }
  • 相关阅读:
    Centos7 安装 Nginx
    Centos7 安装Php7 (貌似没成功)
    Centos7 安装 Mysql (Ubuntu)
    Centos7 安装apache(LAMP)
    Tp5 写类下商品计算数量
    Tp5 写随机数(商品货号)
    Tp5的 多项搜索框(下拉框+输入框)
    centos7 安装python3
    centos 安装notepad++
    用selenium控制已打开的浏览器
  • 原文地址:https://www.cnblogs.com/cuijinlong/p/7243898.html
Copyright © 2020-2023  润新知