📄 jdbcconnect.java
字号:
/**
* Copyright (c) 2002, Siddhartha P. Chandurkar siddhartha@visioncodified.com
* All rights reserved.
* Licensed under the Academic Free License version 1.1
* See the file LICENSE.TXT for details.
* LICENSE.txt is located in the directory <install-directory>\Jenerator
* of your Jenertaor Installation.
*
**/
package com.jenerator.dbaccess;
/*<Imports>*/
import com.jenerator.struct.app.AppConfigStruct;
import com.jenerator.util.Configurator;
import org.apache.log4j.Logger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/*</Imports>*/
/**
* JDBCConnect
* This class is used to connect to the Database using JDBC. It reads all the
* connection configuration properties from the Property Reader
* @PropertyReader, XmlReader
* @version 0.9.0
* @author $Author$ Siddhartha
*/
class JDBCConnect {
//ATTRIBUTES
//The DB user name
private static String usrName;
//The DB password
private static String password;
//The DB url
private static String url;
//The DB JDBC driver
private static String driver;
//logger
private static Logger log = Logger.getLogger(com.jenerator.dbaccess.JDBCConnect.class.getName());
//The structure which contains the Application configurations.
private static AppConfigStruct configStruct;
//CONSTRUCTORS
/**
* JDBCConnect
* Gets the Application Configuration Structure
*/
public JDBCConnect() {
configStruct = Configurator.getInstance().getConfigStructs().getAppConfigStruct();
readConfiguration();
try {
Class.forName(driver);
} catch (Exception e) {
e.printStackTrace();
}
}//JDBCConnect
//METHODS
/**
* readConiguration
* Reads information from the property file
*/
private void readConfiguration() {
usrName = configStruct.getUserName();
password = configStruct.getPassword();
url = configStruct.getUrl();
driver = configStruct.getJdbcDriver();
log.info("Connecting to url " + url);
log.info("UserName " + usrName);
log.info("Password " + password);
log.info("Driver " + driver);
}//readConfiguration
/**
* getConnection
* It returns the JDBC connection
*/
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(url, usrName, password);
}//getConnection
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -