zoukankan      html  css  js  c++  java
  • JDBC工具类

    package com.zw.tool;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    public class Tool {

     private static Connection conn=null;
     private static Statement st=null;
     private static ResultSet rs=null;
     
     public static Connection getConnection(){
      try {
       Class.forName("oracle.jdbc.driver.OracleDriver");
       String url="jdbc:oracle:thin:@localhost:1521:orcl";
       conn=DriverManager.getConnection(url,"scott","tiger");
      } catch (ClassNotFoundException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      } catch (SQLException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
      }
      
      return conn;
      
     }
     
     public static void close(Connection conn,Statement ps,ResultSet rs){
      try {
       if(rs!=null)
       rs.close();
      } catch (SQLException e) {
       e.printStackTrace();
      }finally{
       try {
        if(ps!=null)
         ps.close();
       } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }finally{
        try {
         if(conn!=null)
         conn.close();
        } catch (SQLException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }
       }
      }
      
      
     }
    }

  • 相关阅读:
    转:Caused by: java.lang.NoSuchMethodError: org.apache.log4j.Category.log
    maven安装
    eclipse安装插件
    java.lang.ClassNotFoundException: com.*.listener.ConfigInfoReader
    oracle
    myeclipse中文乱码,JSP页面乱码
    ansible 列表变量、字典变量
    python模块
    python函数
    python数据类型2
  • 原文地址:https://www.cnblogs.com/alvin-perfect/p/4390076.html
Copyright © 2011-2022 走看看