JDBC and database access

Slow day today, so I finally (after 2 years of saying I’d give it a go) got around to trying to use JDBC.

I wrote a simple class to query a mySql database. It worked like a charm! Now all I need to learn is good design practice (which could, I fear, include Beans). I’m not entirely sure how the object model matches up to the database structure – I guess that this is what I need to learn…
import java.sql.*;
import java.util.Properties;

public class JDBCTest {
public static void main( String args[] ){
Connection conn= null;
String cURL = "jdbc:mysql://localhost/jtest";
Properties p = new Properties();



conn = DriverManager.getConnection( cURL, p );

Statement s = conn.createStatement();
ResultSet r = s.executeQuery( "SELECT * FROM jtable WHERE iID = 1" );
System.out.println ( r.getString("cFEN"));
catch ( Exception e ) {
finally {
if( conn != null ) {
try { conn.close(); }
catch ( Exception e ) {}

JDBC and database access

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.