import java.util.*;
import java.sql.*;

public class JDBCExample
{
	public static void main (String[] args)
	{
		String user = "monty";
		String password = "some_pass";
		String url = "jdbc:mysql://localhost:3306/sample";
		String driver = "com.mysql.jdbc.Driver";
		
		Connection connection = null;
		Statement statement = null;
		ResultSet resultSet = null;
		try
		{
			Class driverClass = Class.forName(driver);
			connection = DriverManager.getConnection(url, user, password);
			statement = connection.createStatement();
			resultSet = statement.executeQuery("SELECT CURRENT_TIME");
			if (resultSet.next())
			{
				System.out.println("CURRENT_TIME: " +resultSet.getString(1));
			}
			else
			{
				System.out.println("No rows found in ResultSet");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		finally
		{
			if (resultSet != null)
			{
				try
				{
					resultSet.close();
				}
				catch (Exception ex){}
			}
			if (statement != null)
			{
				try
				{
					statement.close();
				}
				catch (Exception ex){}
			}	
			if (connection != null)
			{
				try
				{
					connection.close();
				}
				catch (Exception ex){}
			}
		}	
	}
}