Posts

Database connection with mysql in Java

Today I will show you how to connect the Java application with the MySQL DB. MySQL and Java both are the open source and freeware. For the java and mysql connectivity I use the “mysql-connector-java-5.0.7.jar” file You can download the mysql-connector-java-5.07.jar Click here Syntax for the jdbc-mysql connection Class . forName ( "com.mysql.jdbc.Driver" ) ; Connection conn = null ; conn = DriverManager.getConnection( "jdbc:mysql://hostname:port/dbname","username", "password"); Following code demonstrate the connection between jdbc-mysql .Here I create a file on which I save the connection string on a encrypted format and use the encrypted data for the further connection. public Connection db_con=null; public String ip_address; public String user_name; public String password; public String db_name; public void DB_Connect() { try {        String fname="Osettings.sys...