Package DB;
Import java.io. *;
Import java.sql. *;
Import java.util. *;
PUBLIC CLASS DBCONNECTION {
CONNECTION CONN;
StMT;
ResultSet Rset;
PRIVATE STRING Password;
Private string URL;
PRIVATE STRING User;
Private string JDBC;
Public dbconnection () {
}
Public Boolean OpenConnection () throws sqlexception {
System.out.println ("ksjfsa");
InputStream is = getClass (). GetResourceAsStream ("db.txt"); // Take a profile
Properties Prop = New Properties ();
Try {
Prop.Load (IS);
System.out.println ("Prop");
}
Catch (IOException EX) {
}
IF (is! = null) {
Try {
Is.close ();
}
Catch (IOException EX1) {
}
JDBC = Prop.GetProperty ("driver");
URL = Prop.GetProperty ("URL");
User = Prop.getProperty ("User");
Password = prop.getProperty ("password");
Try {
Class.Forname (JDBC);
}
Catch (classnotfoundexception ex2) {
EX2.PRINTSTACKTRACE ();
}
CONN = DriverManager.getConnection (URL, User, Password);
STMT = conn.createstatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_read_only);
Return True;
}
Public ResultSet ExceuteQuery (String Query) throws Sqlexception {
Return Stmt.executeQuery (Query);
}
Public void executeUpdate (string query) throws sqlexception {
Stmt.executeUpdate (query);
}
Public void close () {
Try {
IF (conn! = null) {
CONN.CLOSE ();
}
IF (stmt! = null) {
Stmt.close ();
}
IF (Rset! = null) {
Rset.Close ();
}
}
Catch (Sqlexception EX) {
}
}
Public void finalize () {
THIS.CLOSE ();
Public void cloosest () {
STMT = NULL;
Rset = NULL;
}
}
Profile
// filename db.txt
Driver = com.microsoft.jdbc.sqlser.sqlserverdriver
URL = JDBC: Microsoft: SQLServer: //192.168.0.122: 1433; DatabaseName = CUSER = SA
Passwor =