FileDocCategorySizeDatePackage
DatabaseConnector.javaAPI DocExample722Wed Apr 05 20:05:42 BST 2006None

DatabaseConnector.java

 package com.oreilly.ajax;

import java.sql.Connection;
import java.sql.DriverManager;

public class DatabaseConnector {
	
	 public static Connection getConnection() {
	        Connection con = null;
	        String driver = "com.mysql.jdbc.Driver";
	        try {
	            Class.forName(driver).newInstance();

	        } catch (Exception e) {
	            System.out.println("Failed to load mySQL driver.");
	            return null;
	        }
	        try {
	            con = DriverManager
	                    .getConnection("jdbc:mysql:///AJAX?user=ajax&password=aardvark");

	        } catch (Exception e) {
	            e.printStackTrace();
	        }
	        return con;
	    }
}