Connect to MySQL in Java

It’s been too long, I didnt get time to post anything OpenSource.
So here I am again with one simple class Database, to connect to MySQL in Java.
You can use this class in 2 ways –

  1. Specifying user,pwd and database name to connect
  2. Specifying connection ID and class will load rest of the variables from CONFIG file

Here I will post the Database class only, class to read config file and loading properties will be posted in different post.

The Database

And here is how we are going to use this class:

Now you can traverse record rs set in a way you want…

We will shortly see how we are going to use Config class and its usage.

Summary

So now yo have seen how its easy to connect to MySQL in Java. I hope you find this example useful and you can use in any of your assignment or project.

Tags:,

Add a Comment

Your email address will not be published. Required fields are marked *