zoukankan      html  css  js  c++  java
  • android 学习

    DBUtil层

    package com.lunwen.DBUtil;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class DBUtil {
        
        public static String db_url = "jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=utf8";
        public static String db_user = "root";
        public static String db_pass = "20194015";
        
        public static Connection getConn () {
            Connection conn = null;
            
            
            try {
                            Class.forName("com.mysql.jdbc.Driver");
                
                conn = DriverManager.getConnection(db_url, db_user, db_pass);
                
                
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            return conn;
        }
        public static void main(String[] args) {
            getConn();
        }
        
        /**
         * @param state
         * @param conn
         */
        public static void close (Statement state, Connection conn) {
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        
        public static void close (ResultSet rs, Statement state, Connection conn) {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
    }
  • 相关阅读:
    61组第二次团队作业
    饮水机电路图工作原理及电路图分析
    七种基础模拟电路的用法
    C语言判断一个数是奇数还是偶数
    F28335 UART串口配置及数据发送
    F28335 SPI配置及收发数据
    电容的九大功能
    查询接口---flask+python+mysql
    python参数传递
    java基础
  • 原文地址:https://www.cnblogs.com/Nojava/p/14908875.html
Copyright © 2011-2022 走看看