JDBC Backup record

Source: Internet
Author: User

package com.yjm.ldapdao;import java.sql.connection;import java.sql.drivermanager;import  java.sql.preparedstatement;import java.sql.resultset;import java.sql.sqlexception;import  Org.apache.log4j.logger;public class daodb { connection conn; preparedstatement  pst; ResultSet rs; public static Logger logger =  Logger.getlogger (Daodb.class);  public daodb ()  { } public connection conn ()  {  try {   if  (conn == null)  {     if  (LdapConf.log.equals ("yes"))  {     logger.info ("Create Connection ...");     }    conn = drivermanager.getconnection (LdapConf.dburl,       ldapconf.dbusername, ldapconf.dbpassword);   }  }  catch  (sqlexception e)  {   logger.info ("Failed to create database connection ...");    logger.info (e);    E.printstacktrace ();   }  return conn; } public void closeconn ()  {  try {   if  (rs != null)  {     Rs.close ();    if  (LdapConf.log.equals ("yes"))  {      Logger.info ("Close rs");    }   }   if  (pst ! = null)  {    pst.close ();    if  (LdapConf.log.equals (" Yes "))  {     logger.info (" Close pst ");    }    }   if  (Conn != null)  {    conn.close ();     logger.info ("Close conn");   }  } catch  ( Sqlexception e)  {    Logger.info (e);    e.printstacktrace ();   } } public preparedstatement  pre (String sql)  {  try {   logger.info ("Create  pst ...");    pst = conn.preparestatement (sql, resultset.type_scroll_insensitive,      resultset.concur_read_only);  } catch  (SQLException e)  {    e.printstacktrace ();   }  return pst; } public resultset  rs ()  {  try {   logger.info ("Get result set ...");    rs =  pst.executequery ();  } catch  (sqlexception e)  {    Logger.info (e);    e.printstacktrace ();  }  return rs; }  Public void closepreparedstatement ()  {  try {   if  (PST  != null)  {  &Nbsp; pst.close ();     logger.info ("Close pst");    }  }  catch  (sqlexception e)  {   e.printstacktrace ();  } }  Public void closeresultset ()  {  try {   if  (rs !=  NULL)  {    rs.close ();     logger.info ("Close rs");    }  } catch  (sqlexception e)  {   logger.info (e);    e.printstacktrace ();   } }}

Write your own JDBC backup reuse record as required.

JDBC Backup record

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.