JDBC application - database connection complete works

xiaoxiao2021-03-06  54

Article publication: Wendea

Published: 2004-07-30

This is an infrastructure that mainly introduces the application of JDBC in the popular database (SQL Server, Oracle). But it's all personal opinions, so I can't guarantee that it is completely correct, for reference only, if there is something different opinion, I can point out in the comments, I will make corresponding modifications. :) Under normal circumstances, when using the JDBC and other things, the code is compared to the commonly used database code may be: private connection conn private string poolur = ""; private string drivername = ""; private string user = "Private String Pass = ""; Private DBConnProxy Proxy; // Written Class, Control Database Access Scheme PUBLIC Object getConn () {Try {Properties Prop = New Properties (); Prop.SetProperty; Prop.SetProperty; Prop.SetProperty ("Password", pass); driver mydriver = (driver) Class.Forname (DRIVERNAME) .newinstance (); conn = mydriver.connect (poolurl, prop); // or conn = mydriver.connect (PoolUrl, NULL); When is the special manager with me? / * Or: class.Forname (drivername); conn = drivermanager.getConnection (PoolURL, User, Pass); * /} catch (Exception E) {system.out.println ("Open Database Error / N" E.getMessage ());} If (! proxy.getdb ()) {this.close () Return Null;} Return Conn;} DRIVERNAME, POOLURL, USER, PASS can be obtained by reading an XML file or a normal attribute file. But even SQLServer is still Oracle, just change the configuration. They can be used in Sun.jdbc.odbc.jdbCodbcdriver. Corresponding to Pool = "JDBC: ODBC: Test", user, pass slightly can also be unique: sqlserver: weblogic.jdbc.msqlserver4.driver (online) corresponding poolurl = "JDBC: WebLogic: MSSQLServer4: CEIC@127.0.0.1 "// CEIC is the database name, 127.0.0.1 is a data source location, which can be a remote database, user, pass slightly oracle: Oracle.jdbc.driver.OracleDriver (Class12.zip, installed Oracle) corresponds to JDBC : Oracle: Thin: Scott/tiger@10.1.103.234: 1521: SP "Scott / Tiger connection identity username / password, 10.1.103.234, data source IP, 1521: Port (default is 1521). SP points to the database name User If the Pass is slightly used by the WebLogic database connection, it can pass CONTEXT CTX = New InitialContext (); DataSource DS = (DataSource) CTX.lookup ("ForceCDataSource"); // forceicDataSource is a matching DataSource. You can also pass and above A unified method to call.

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

New Post(0)