Sunday, March 20, 2016

Connecting to MySql from java with Maven

In this example we will be creating a simple maven java project to connect to the local mysql instance, without actually installing any jdbc connector and setting it to classpath (maven will take care of this :))

1. Add MySQL connector maven dependency in the pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns=""



2. Sample java source file: Connecting to local mysql instance and listing tables;

package com.automatethebox.mysql_connect_maven;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class MySqlConnectionWithMaven {

    public static void main(String[] args) {

        // Databases url (here 'information_schema' is database name)
        String databaseUrl = "jdbc:mysql://localhost/information_schema";
        String jdbcConnectorClass = "com.mysql.jdbc.Driver";
        String mysqlUser = "root";
        String myUserPass = "Admin@123";
        String query = "Select distinct(table_name) from INFORMATION_SCHEMA.TABLES";

        try {
            Connection connection = DriverManager.getConnection(databaseUrl, mysqlUser, myUserPass);
            Statement statement = connection.createStatement();
            ResultSet resultSet = statement.executeQuery(query);
            while ( {
                String tableName = resultSet.getString(1);
                System.out.println("Table : " + tableName);
        } catch (ClassNotFoundException e) {
        } catch (SQLException e) {

Friday, March 4, 2016

Disable Java JVM Default DNS Caching

You can disable the Java Virtual machine default DNS caching following any of the below methods
( By Default java 1.6 caches all the DNS queries ):

  • Method 1(Changes while staring up JVM)
    • Add while starting up the JVM.

  • Method 2(Changes in java config file)
    • Add/Edit the property networkaddress.cache.ttl=0 in %JRE%/lib/security/ file. Here JRE refers to Java Runtime Environment folder.

  • Method 3(Changes in your code)
    • Set the property in you java code as"networkaddress.cache.ttl", "0" );

AWS Certified Solutions Architect Associate - AWS Introduction - Questions

All the Best !!! Show Result !! Try Again !! ×