Method Layer!

Source: Internet
Author: User

Package poster.util;
Import java.sql.*;
Import Java.text.SimpleDateFormat;
Import Java.util.Date;

Import Javax.xml.crypto.Data;
public class DBHelper {
private static final String url= "Jdbc:oracle:thin: @localhost: 1521:ORCL";
private static final String user= "BBS";
private static final String password= "123";
private static Connection Con=null;
static{
try{
Class.forName ("Oracle.jdbc.driver.OracleDriver");
}catch (ClassNotFoundException e) {
E.printstacktrace ();
}
try{
Con=drivermanager.getconnection (URL, user, password);
}catch (SQLException e) {
E.printstacktrace ();
}
}
/**
* Access to the connection image before each operation
* @throws SQLException
*/
public static void Getconnection () throws sqlexception{
Con=drivermanager.getconnection (URL, user, password);
}
/**
* @param sql
* @param objects
* @return Returns the number of rows affected (by adding, deleting, modifying the action)
* @throws SQLException
*/
public static int ExecuteNonQuery (String sql,object...objects) throws sqlexception{
Getconnection ();
PreparedStatement pstm=con.preparestatement (SQL);
for (int i=0;i<objects.length;i++) {
Pstm.setobject (i+1, objects[i]);
}
int result=pstm.executeupdate ();
CloseConnection ();
return result;
}
/**
* @param sql
* @param objects
* @return access to the aggregate of the inquiries according to the SQL sentence
* @throws SQLException
*/
public static ResultSet ExecuteQuery (String sql,object...objects) throws sqlexception{
Getconnection ();
PreparedStatement pstm=con.preparestatement (SQL);
for (int i=0;i<objects.length;i++) {
Pstm.setobject (i+1, objects[i]);
}
ResultSet Set=pstm.executequery ();
return set;
}
/**
* You need to close each time you run out of connections
* @throws SQLException
*/
public static void CloseConnection () throws sqlexception{
if (con!=null) {
Con.close ();
}
}
/**
* Time
* @return
*/
public static String Csss () {
Date D=new date ();
SimpleDateFormat df=new SimpleDateFormat ();
String S=df.format (d);
return s;
}
}

Method Layer!

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.