You must put the code where you want to get connection to your database. And then simply try executing queries on the database through java and when you are done, close the connection. What's so hard?