Database Connection Java

Source: Internet
Author: User

Package AAA;

Import java. SQL .*;
Import java. Io .*;
Import java. util .*;
Import java. Lang .*;
Import java.net .*;

Public class dbconn {
 
Connection conn = NULL;
Resultset rs = NULL;
 
Private string link = "JDBC: oracle: thin: @ 192.168.10.120: 1521: dbname ";
Private string name = "username ";
Private string Password = "password ";
 
Public dbconn (){
Try {
Class. forname ("oracle. JDBC. Driver. oracledriver"). newinstance ();
}
Catch (Java. Lang. Exception e ){
System. Err. println ("datadriver is wrong DBASE ():" + E. getmessage ());
}
}

 

 
Public resultset executequery (string SQL ){
Rs = NULL;
Try {
Connection conn = drivermanager. getconnection (link, name, password );
Statement stmt = conn. createstatement (resultset. type_scroll_sensitive, resultset. concur_updatable );
System. Out. println (SQL );
Rs = stmt.exe cutequery (SQL );
}
Catch (sqlexception ex ){
System. Err. println ("query is wrony dbase.exe cutequery ()" + ex. getmessage ());
}
Return Rs;
}
 
Public Boolean executeupdate (string SQL ){
Boolean bupdate = false;
Try {
Connection conn = drivermanager. getconnection (link, name, password );
Statement stmt = conn. createstatement ();
Int rowcount = stmt.exe cuteupdate (SQL );
If (rowcount! = 0) bupdate = true;
}

Catch (sqlexception ex ){
System. Err. println ("update is wrony,dbase.exe cuteupdate ()" + ex. getmessage ());
}
Return bupdate;
}


Public void connclose (){

Try {

If (Conn! = NULL) Conn. Close ();
If (RS! = NULL) rs = NULL;

}
Catch (sqlexception ex ){
System. Out. println ("connclose" + ex. getmessage ());
}
}
 
}

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.