I will first admit to being new to java coding. Recently, I decided to finally sit down and train myself in the language.
As part of my self-imposed assignment I am building a webapp using a MySQL back-end. A while back, I had built this on a PHP/nuSOAP/MySQL design and now I want to replicate in Java. The architecture for the original design had the following:
1) Relational Database (MySQL 5.1)
2) PHP global variables (to re-use without having to re-write a lot)
3) Central PHP functions file
4) SOA functions file with WSDL creation
5) PHP front end which interacted with the functions file
In Java, I have:
1) Same Database
2) config.properties file with things like (dbuser, dburl, dbpassword, dbdriver, etc.)
3) dbConnection class
Now, I can connect to the database using the following code:
This works as I am able to get the "Database connection established" message in the console. But what I want this class to do is to call two methods that I can access from an external java client (to be constructed):
In this fashion, I can have an external client call 'dbConnect()' and connect to DB, perform SQL queries, call stored procedures, and all that good stuff... and then call 'dbClose()' when is all done! For me, in PHP, this was a very modular approach to handle the database connections from a different functions' file.
The source code above is divided on two sections "SECTION A and SECTION B". Section A is the connection code and SECTION B. The latter is what I need help on. I was thinking about enclosing my SECTION A under a 'public static dbConnect()' and SECTION B to be a 'public static dbClose()'. However, how would I close a connection on a separate method?
Any advice on how to create this 'connection manager'? Thanks in advance