Use the hard-connected Oracle database part of the code import java.util. *; Import java.sql. *; Import java.io. *;
public class DBConBean {private String jdbcdriver = new String (); private String url = new String (); private String user = new String (); private String password = new String (); private Connection conn = null;
Public dbconbean () {getConnection ();
Private void getConnection () {// read the preset database related information from the Properties file Properties Prop = New Properties (); try {inputstream is = getClass (). getResourceAsSstream ("/ database-conf.properties"; prop. LOAD (IS); if (is! = null) is.close ();} catch (ooException e) {system.out.print ("[dbconnection] open file error");} jdbcdriver = prop.getProperty ("JDBCDRiver "); Url = prop.getProperty (" URL "); user = prop.getProperty (" user "); password = prop.getProperty (" password "); try {class.forname (jdbcdriver);} catch (ClassNotFoundException E ) {} // Generate connection try {conn = drivermanager.getConnection (URL, User, Password);} catch (sqlexception e) {}}
Public Connection getConn () {// Returns the connected interface Return Conn;}
Public void close () throws sqlexception {if (conn! = null) conn.close ();
}