MySQL Connection object
Jdbc.driver=com.mysql.jdbc.driver
Files found by jdbc.url=jdbc:mysql://localhost:3306/
Jdbc.user=root
jdbc.password= The password you set yourself
Oracle Connection Object
Jdbc.driver=oracle.jdbc.driver.oracledriver
Jdbc.url=jdbc:oracle:thin: @localhost: 1521:ORCL
Jdbc.user=scott
jdbc.password= The password you set yourself
Gets the tool class for the database connection object (made into a package to make it easy to call)
Package Com.etc.untl;import Java.sql.*;import Java.util.properties;import java.io.filenotfoundexception;import Java.io.filereader;import java.io.ioexception;/** * Tool class to get database connection objects * @author Administrator * @version 1.0 */public Class JD Bcuntl {private static string Driverclass = null;private static string url = null;private static string user = Null;privat e static String password = null;//Gets the database-driven information in the jdbc.properties through a static block and initializes the static member variable static{properties props = new Properties (); try {props.load (new FileReader ("Jdbc.properties"));d Riverclass = Props.getproperty ("Jdbc.driver"); URL = Props.getproperty ("Jdbc.url"), user = Props.getproperty ("Jdbc.user");p Assword = Props.getproperty ("Jdbc.password");} catch (FileNotFoundException e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ()}} /** * Creates a database connection object based on the database drive information obtained and returns * @return Connection object * @throws Exception */public static Connection getconnection () throws Excep Tion{connection conn = null; Class.forName (driverclass); conn = Drivermanager.getconnection (url, user, password); return conn;} /** * Method of unifying JDBC Resources off * @param RS Result set object * @param stmt Statement Object * @param conn Connection object * @throws SQLException */public static void cl OSE (ResultSet rs,statement stmt,connection conn) throws Sqlexception{if (rs! = null) {Rs.close (); rs = null;} if (stmt! = null) {stmt.close (); stmt = null;} IF (conn! = null) {conn.close (); conn = null;}}}
Gets the tool class for the database connection object