Posts

Showing posts from March, 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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.automatethebox</groupId> <artifactId>mysql-connect-maven</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <vers…

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 -Dsun.net.inetaddr.ttl=0 while starting up the JVM.
Method 2(Changes in java config file)Add/Edit the property networkaddress.cache.ttl=0 in %JRE%/lib/security/java.security file. Here JRE refers to Java Runtime Environment folder.
Method 3(Changes in your code)Set the property in you java code as java.security.Security.setProperty("networkaddress.cache.ttl", "0" );