
import java.sql.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.sql.DatabaseMetaData;

public class Connect
{
	public static void main(String[] argv) throws IOException, SQLException
	{
		Connection c = null;

		try
		{
			c = getConnection();

			System.out.println("Connected");

			DatabaseMetaData meta = c.getMetaData();

			System.out.println("Driver Name: " + meta.getDriverName());
			System.out.println("Driver Version: "+ meta.getDriverVersion());

		} catch (SQLException e)
		{
			System.err.println("SQLException: " + e.getMessage());
			System.exit(1);
		} finally
		{
			if (c != null)
				c.close();
		}
	}

	public static Connection getConnection() throws SQLException, IOException  
	{    
		Properties props = new Properties();  
		FileInputStream in = new FileInputStream("database.properties");  
		props.load(in);  
		in.close();  

		String drivers = props.getProperty("jdbc.drivers");  

		if (drivers != null)  
			System.setProperty("jdbc.drivers", drivers);  

		String url = props.getProperty("jdbc.url");  
		String username = props.getProperty("jdbc.username");  
		String password = props.getProperty("jdbc.password");  

		return DriverManager.getConnection(url, username, password);  
	}  
}

