zoukankan      html  css  js  c++  java
  • JDBC_JDBCUtils1.0

    package cn.JDBCUtils.com;
    
    import java.io.InputStream;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.SQLException;
    import java.util.Properties;
    
    public class JDBCUtils {
        private static Properties  props =null;
        static{
            try{
                InputStream in = JDBCUtils.class.getClassLoader()
                                .getResourceAsStream("dbconfig.properties");
                props = new Properties();
                props.load(in);}catch(Exception e){
                    throw new RuntimeException();
                }
            try{
                Class.forName(props.getProperty("driverClassName"));
            }catch (Exception e) {
                throw new RuntimeException();
            }
            
        }
        public static Connection getConnection() throws SQLException{
            /*
             * 1、加载配置文件
             * 2、加载驱动类
             * 3、调用DriverManager.getConnection()
             * */
            return DriverManager.getConnection(props.getProperty("url"),props.getProperty("username"), props.getProperty("password"));
            
        }
    }

    //四大参数.propertise

    driverClassName=com.mysql.jdbc.Driver
    url=jdbc:mysql://127.0.0.1:3306/mydb1
    username=root
    password=123
  • 相关阅读:
    OSI模型白话
    并发
    初始化与清理
    多线程
    recyclerview Adapter
    recyclerview刷新
    surfaceview
    viewgroup绘制流程
    view配置
    项目遇到的问题
  • 原文地址:https://www.cnblogs.com/wangyinxu/p/7428161.html
Copyright © 2011-2022 走看看