java.lang.Object
org.seppiko.commons.utils.jdbc.ConnectionUtil
JDBC Connection util
- Author:
- Leonard Woo
-
Method Summary
Modifier and TypeMethodDescriptionstatic ConnectiongetConnection(String url, String username, String password) Create Connectionstatic ConnectiongetConnection(String driverClazzName, String url, String username, String password) Create Connectionstatic DataSourcegetDataSourceWithJNDI(String jndiName) Get DataSource with JNDI name
-
Method Details
-
getConnection
public static Connection getConnection(String driverClazzName, String url, String username, String password) throws SQLException, ClassNotFoundException, IllegalArgumentException, NullPointerException Create Connection- Parameters:
driverClazzName- driver class name.url- JDBC URL.jdbc:subprotocol:subnameusername- Database username.password- Database password.- Returns:
- a connection to the URL.
- Throws:
SQLException- if a database access error occurs.ClassNotFoundException- if the driver class cannot be located.IllegalArgumentException- if the driver class is null.NullPointerException- JDBC URL is null.
-
getConnection
public static Connection getConnection(String url, String username, String password) throws SQLException, NullPointerException Create Connection- Parameters:
url- JDBC URL.jdbc:subprotocol:subname.username- Database username.password- Database password.- Returns:
- a connection to the URL.
- Throws:
SQLException- if a database access error occurs.NullPointerException- JDBC URL is null.
-
getDataSourceWithJNDI
Get DataSource with JNDI name- Parameters:
jndiName- JNDI name.- Returns:
- a datasource to the jndi name.
- Throws:
NamingException- if a naming exception is encountered or in a naming exception is encountered.
-