• jdbc链接数据库


    package com.maya.hanqi.jdbctest;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class JdbcConnectUtil { //工具类
        private static final String USERNAME = "test";
        private static final String PASSWORD = "test";
        private static final String URL = "jdbc:oracle:thin:@localhost:1521:xe";
        private static final String DRIVERCLASSNAME = "oracle.jdbc.OracleDriver";
        
        public static Connection getConnection(){
            Connection conn = null;
            try {
                Class.forName(DRIVERCLASSNAME);
                conn = DriverManager.getConnection(URL,USERNAME,PASSWORD);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }        
            return conn;        
        }
        public static void destroy(Connection conn,Statement sm,ResultSet rs){
            if (conn!=null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                conn = null;
            }
            if (sm!=null) {
                try {
                    sm.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                conn = null;
            }
            if (rs!=null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
                conn = null;
            }
        }
        public static void main(String[] args) {
            System.out.println(getConnection());
            
        }
    }
  • 相关阅读:
    spark 中划分stage的思路
    如何带人
    技术管理
    学会谈判
    绩效评估与绩效反馈
    企业文化如何落地
    绩效沟通的best原则
    Area POJ
    Cows POJ
    Grandpa's Estate POJ
  • 原文地址:https://www.cnblogs.com/donghb/p/7422832.html
Copyright © 2020-2023  润新知