• jdbc-------JDBCUtil类 工具类


    jdbcutil 主要处理的是 连接数据库, 和关闭各个流

    1, 数据库连接的配置信息: mysql.properties (在工程的目录下)个人配置

    url=jdbc:mysql://localhost:3306/test
    driver=com.mysql.jdbc.Driver
    username=root
    password=123

    2, 获取连接

    读取配置信息,加载驱动。连接。(这个在后面的例子常用到)

    
    

    package com.ljs.util;

    import java.io.File;
    import java.io.FileInputStream;

    
    

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.Properties;


    public
    class JDBCUtil { private static String url; private static String user; private static String password; private static String driver; static{ try { Properties properties = new Properties(); FileInputStream fis = new FileInputStream(new File("mysql.properties")); properties.load(fis); url = properties.getProperty("url"); user = properties.getProperty("username"); password = properties.getProperty("password"); driver = properties.getProperty("driver"); Class.forName(driver); } catch (Exception e) { e.getMessage(); } } public static Connection getConn() throws Exception{ Connection connection = DriverManager.getConnection(url, user, password); return connection; } public static void close(ResultSet resultSet, PreparedStatement preparedStatement, Connection connection){ try { if (resultSet != null) { resultSet.close(); } if(preparedStatement != null ){ preparedStatement.close(); } if(connection != null ){ connection.close(); } } catch (SQLException e) { throw new RuntimeException(); } } }
  • 相关阅读:
    RequireJS进阶(二)
    JavaScript判断元素为数字的奇异写法
    RequireJS进阶(三)
    RequireJS进阶(一)
    读Ext之十四(Ext元素)
    JavaScript中__proto__与prototype的关系
    工作流术语
    一个例子(Hello World)
    无题
    再谈调用子流程(1)
  • 原文地址:https://www.cnblogs.com/lijins/p/10122063.html
Copyright © 2020-2023  润新知