Java is connected to Oracle, takes the IO file content, and replaced (original)!

xiaoxiao2021-03-06  121

Package Common; import java.sql. *; import java.io. *; import javax.naming. *; import javax.sql. *; import java.util. *;

Public class dbaction {public connection conn = null; public preparedStatement Stmt = null;

public Properties getProperties (String str) {Properties properties = new Properties (); try {InputStream is = getClass () getResourceAsStream ( "/" str);. properties.load (is); (! is = null) if is. CLOSE ();} catch (ooException oException) {system.out.println ("Open config file failure.");} catch (nullpointerexception e) {system.out.println ("is is null";} returnified; } Public synchronized void dbconnect () {string strcon = NULL; Properties Properties = GetProperties ("Datasour ce.properties "); String username = properties.getProperty (" username "); String password = properties.getProperty (" password "); String hostname = properties.getProperty (" hostname "); String hostip = properties.getProperty (" Hostip "); string hostport = Properties.getProperty (" hostport ");

try {Class.forName ( "oracle.jdbc.driver.OracleDriver");} catch (ClassNotFoundException classnotfoundexception) {System.out.println ( "Could not load the driver."); classnotfoundexception.printStackTrace ();} strCon = " jdbc: oracle: thin: @ " hostip ": " hostport ": " hostname; try {conn = DriverManager.getConnection (strCon, username, password);} catch (SQLException sqlexception) {System.out.println (" Creat Connection Error. "); SQLException.PrintStackTrace ();} // Try {// context initContext = new initialContext (); // Connection pool // context envconText = (Context INITCONTEXT.LOOKUP ("java: / comp / ENV"); // DataSource DS = (Datasource) ENVCONTEXT.LOOKUP ("JDBC / Oracle"); // conn = ds.getConnection (); //} // catch (Namingexception ne) {// ne.PrintStackTrace (); //} // catch (sqlexception se) {// se.printstacktrace (); //}} public string sqlsearch (string str) {string sql = null; Properties Properties = getProperties ("SQL.Properties"); SQL = Properties.getProperty (STR); RETURN SQL;

} Public ResultSet DBSelect (String SQL) {ResultSet RS = NULL; try {this.stmt = conn.preparestatement (sql.trim ()); rs = this.stmt.executeQuery ();} catch (sqlexception e) {e. PRINTSTACKTRACE ();} return rs;} public resultset dbselect (string sql, string str1) {resultset = null; try {this.stmt = conn.preparestatement (SQL.TRIM ()); this.stmt.setstring (1, Str1);} Catch (SQLEXCEPTION E) {E.PrintStackTrace ();} Return Rs;} public resultset dbselect (String SQL, String str1, string str2) {Resultset RS = null; try {this.stmt = conn.preparestatement (SQL.TRIM ()); this.stmt.setstring (1, str1); this.stmt.setstring (2, str2); rs = this.stmt.executeQuery );} CatCh (SQLEXCEPTION E) {E.PrintStackTrace ();} return} public int dBUPD (String SQL) {int RTNCD = 0; try {stmt = conn.preparestatement (SQL); RTNCD = stmt.executeUpdate ); If (RTNCD! = 0) RTNCD = 1;

} CatCH (Exception E) {E.PrintStackTrace ();} Return RTNCD;} public int dbdl (String SQL) {INT RTNCD = 0; try {stmt = conn.preparestatement (SQL); RTNCD = stmt.executeUpdate (); IF (RTNCD! = 0) RTNCD = 1;} Catch (Exception E) {E.PrintStackTrace ();} return}} return} public int DBADD (String SQL) {INT RTNCD = 0; try {stmt = conn.preparestatement SQL); RTNCD = stmt.executeUpdate (); if (RTNCD! = 0) RTNCD = 1;} Catch (Exception E) {E.PrintStackTrace ();} return}}}}} public void close () {Try {if (stmt! = Null) stmt.close (); if (conn! = NULL) Conn.close ();} catch (sqlexception e) {E.PrintStackTrace ();}}} public string replasbstr (String string string strfrom, string string) {if (strsource ==

NULL) {return null;} int i = 0; if ((i = strsource.indexof (strfrom, i))> = 0) {char [] csrc = strsource.tochararray (); char [] cto = strto.chararray (); Int Len = strfrom.length (); stringbuffer buf = new stringbuffer (csrc.length); buf.append (CSRC, 0, I); buf.append (cto); //buf.append (CSRC, 0 , i) .append (cto); i = le; int J = i; wh ILE ((i = strsource.indexof (strfrom, i))> 0) {BUF.Append (CSRC, J, IJ); BUF.Append (CTO); //buf.append (CSRC, J, I - J) .append (cto); i = le; j = i;

转载请注明原文地址:https://www.9cbs.com/read-99933.html

New Post(0)