How to make a java program talk to a database

For future reference, here is how to install JDBC (the connector between java and a mysql database):

Download JDBC from Sun: http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1....
Extract the zipped folder
In that folder (at the highest level in the hierarchy of folders and files), there should be a .jar file (a java archive file) called mysql-connector-java-5.0.8-bin.jar.
Copy that into the "lib" folder under the "src" folder that contains your java files
Then in Eclipse go to File-->Properties, which should open a little window with tabs and buttons
Click on the "libraries" tab, highlight the .jar file mentioned above, and then click "add JARs"

As part of your .java file which has the functions you call when you want to interact with the database, you should have a public boolean function called something like OpenDBConnection() .

Inside it should look something like:
try
{
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, "username", "password");
}
catch(ClassNotFoundException cnfex)
{
System.err.println(" Failed to load JDBC driver.");
cnfex.printStackTrace();
System.exit(1);
}
catch(SQLException sqlex){
System.err.println(" Unable to connect.");
sqlex.printStackTrace();
}
return true;

You need to make sure the username and password of your database in this code match that of your database, of course, and that your username's account has all the necessary privileges to change the database.
This code refers to a string variable called "url"; this url variable should be defined somewhere in this .java file, and for reasons not completely known to me, looks something like: private String url = "jdbc:mysql://localhost:3306/assuredlabor". Our db is on a server, and our server's address in Firefox is http://localhost/phpmyadmin/. (We're using the WAMP server software, which comes with apache, php, and msql. It's got a great user interface.) So I don't know why the url is defined as such, but I recommend using the WAMP software, creating a new database, giving it a name, and then defining the url string to be exactly the same as above except with your database's name instead of "assuredlabor."

Then run your java program with this extra code at the beginning:
boolean DBStatus ;
Liukapi myDB = new Liukapi();
DBStatus = myDB.OpenDBConnection();
System.out.println("DBStatus:= " + DBStatus);

And it should print out that DBStatus is true. Hoorah!

-Elena