Here you can find the source of getConnection()
Parameter | Description |
---|---|
ClassNotFoundException | an exception |
SQLException | an exception |
public static Connection getConnection() throws ClassNotFoundException, SQLException
//package com.java2s; //License from project: Open Source License import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Main { private static final String DEFAULT_DRIVER = "oracle.jdbc.driver.OracleDriver"; private static final String DEFAULT_URL = "jdbc:oracle:thin:@127.0.0.1:1521:XE"; private static final String DEFAULT_USERNAME = "SYSTEM"; private static final String DEFAULT_PASSWORD = "SHUBHAM"; /**/*from w w w .j av a2s. c o m*/ * This method return a connection with database * * @return connection * @throws ClassNotFoundException * @throws SQLException */ public static Connection getConnection() throws ClassNotFoundException, SQLException { Class.forName(DEFAULT_DRIVER); Connection connection = DriverManager.getConnection(DEFAULT_URL, DEFAULT_USERNAME, DEFAULT_PASSWORD); return connection; } }