• Oracle数据库连接


    package p5.com.byd.mes.dev.tool;
    
    import java.sql.Connection;
    import java.sql.SQLException;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Savepoint;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    
    public class OracleConnActivity {
       private static final Log log=LogFactory.getLog(OracleConnActivity.class);
       public Connection conn=null;
       public String SQLString="";
       public PreparedStatement psm=null;
       public ResultSet rs=null;
       public Savepoint sp=null;
       public String url="";
       public String user="";
       public String password="";
       public String ActivityName="";
       public String paraStr="";
       
       public OracleConnActivity(){
    	   url="";
    	   user="";
    	   password="";
       }
      public OracleConnActivity(String parURL,String parUSER,String parPASSWORD){
    	  url=parURL;
    	  user=parUSER;
    	  password=parPASSWORD;
      } 
      public boolean getConnect(){
    	  try{
    		  DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    		  conn=DriverManager.getConnection(url,user,password);
    		  conn.setAutoCommit(true);
    	  }catch(SQLException ex){
    		  log.debug(url+"建立数据库连接时发生异常");
    		  log.debug("Error code="+ex.getErrorCode());
    		  log.debug("Error message="+ex.getMessage());
    		  log.debug("sql state=" +ex.getSQLState());
    		  return false;
    	  }
    	  return true;
      }
    public void DisConnect(){
    	try{
            //关闭ResultSet对象
            if (rs != null) {
                rs.close();
            }
            //关闭PreparedStatement对象
            if (psm != null) {
                psm.close();
            }
            //关闭Connection对象
            if (conn != null) {
                conn.close();
            }
    	}catch(SQLException ex){
    		log.debug(url+"关闭数据库连接发生异常");
    		log.debug("Error code = " + ex.getErrorCode());
    		log.debug("Error message = " + ex.getMessage());
    		log.debug("SQL state = " + ex.getSQLState());
    	}
    }
    //	public static void main(String[] args){
    //		OracleConnActivity con=new OracleConnActivity();
    //		con.url="jdbc:oracle:thin:@10.6.68.242:1521:MESSS";
    //		con.user="PS_MES_PSN";
    //		con.password="psndb";
    //		if(con.getConnect()){
    //			try{
    //				con.SQLString="select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')notime from dual";
    //				con.psm=con.conn.prepareStatement(con.SQLString);
    //				con.rs=con.psm.executeQuery();
    //				while(con.rs.next()){
    //					log.debug(con.rs.getString(1));
    //				}
    //			}catch(SQLException ex){
    //				log.debug(ex.getMessage());
    //			}
    //			finally{
    //				con.DisConnect();
    //			}
    //		}
    //		con=null;
    //	}
    }
    
  • 相关阅读:
    MSP430:实时时钟-DS1302
    STM32: TIMER门控模式控制PWM输出长度
    LVM磁盘管理
    python的面向对象,类,以及类的使用
    pymysql模块
    paramiko模块
    正则表达式和re模块
    python3的soker模块实现功能
    根据生日测星座
    多进程,进程池,协程
  • 原文地址:https://www.cnblogs.com/qq1988627/p/6606919.html
Copyright © 2020-2023  润新知