mysql jdbc connection code

package com.test;

import java.sql.*;

 

public class MysqlConnect{

  public static void main(String[] args)throws Exception {

    System.out.println("MySQL Connect Example.");

    Connection conn = null;

    String url = "jdbc:mysql://localhost:3306/";

    String dbName = "test";

    String driver = "com.mysql.jdbc.Driver";

    String userName = "fff";

    String password = "bbb";

    try {

      Class.forName(driver).newInstance();

      conn = DriverManager.getConnection(url+dbName,userName,password);

      System.out.println("Connected to the database");

      conn.close();

      System.out.println("Disconnected from database");

    } catch (Exception e) {

      e.printStackTrace();

    }

  }

}

Comments

Popular posts from this blog

Rails Memcache issues

scp command usage guide

ROR HEROKU Working with file storage like paperclip in heroku for free of cost ( paperclip and dropbox) paperclip-dropbox config | ROR, HEROKU, file storage, paperclip, in heroku, free of cost, paperclip, dropbox, paperclip-dropbox config