import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Random;

import com.sleepycat.db.Database;
import com.sleepycat.db.DatabaseConfig;
import com.sleepycat.db.DatabaseEntry;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.DatabaseType;

public class DbHelper {

	public static Database create(String dbPath, DatabaseType dbType) {
		// database configuration
		DatabaseConfig dbConfig = new DatabaseConfig();

		// dbConfig.setErrorStream(System.err);
		// dbConfig.setErrorPrefix("MyDbs");

		dbConfig.setType(dbType);
		dbConfig.setAllowCreate(true);

		// database

		Database db;
		try {
			File dbFile = new File(dbPath);
			if (!dbFile.exists()) dbFile.createNewFile();
			db = new Database(dbPath, null, dbConfig);

			return db;
		} catch (FileNotFoundException e) {
			System.err.println("Database file not found");
		} catch (DatabaseException e) {
			System.err.println("Failed to open database");
		} catch (IOException e) {
			System.err.println("Failed to create database file");
		}
		return null;
	}

	/*
	 *  To populate the given table with nrecs records
	 */
	static void populateTable(Database my_table, int nrecs ) {
		int range;
		DatabaseEntry kdbt, ddbt;
		String s;

		/*  
		 *  generate a random string with the length between 64 and 127,
		 *  inclusive.
		 *
		 *  Seed the random number once and once only.
		 */
		Random random = new Random(1000000);

		try {
			for (int i = 0; i < nrecs; i++) {

				/* to generate a key string */
				range = 64 + random.nextInt( 64 );
				s = "";
				for ( int j = 0; j < range; j++ ) 
					s+=(new Character((char)(97+random.nextInt(26)))).toString();

				/* to create a DBT for key */
				kdbt = new DatabaseEntry(s.getBytes());
				kdbt.setSize(s.length()); 

				// to print out the key/data pair
				// System.out.println(s);	

				/* to generate a data string */
				range = 64 + random.nextInt( 64 );
				s = "";
				for ( int j = 0; j < range; j++ ) 
					s+=(new Character((char)(97+random.nextInt(26)))).toString();
				// to print out the key/data pair
				// System.out.println(s);	
				// System.out.println("");

				/* to create a DBT for data */
				ddbt = new DatabaseEntry(s.getBytes());
				ddbt.setSize(s.length()); 

				/* to insert the key/data pair into the database */
				my_table.putNoOverwrite(null, kdbt, ddbt);
			}
		}
		catch (DatabaseException dbe) {
			System.err.println("Populate the table: "+dbe.toString());
			System.exit(1);
		}
	}

}

@@ -1,25 +1,4 @@
-import java.io.File;%0A
 impo
@@ -35,36 +35,8 @@
 on;%0A
-import java.io.IOException;%0A
 impo
@@ -611,92 +611,8 @@
 y %7B%0A
-%09%09%09File dbFile = new File(dbPath);%0A%09%09%09if (!dbFile.exists()) dbFile.createNewFile();%0A
 %09%09%09d
@@ -844,93 +844,8 @@
 %22);%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09System.err.println(%22Failed to create database file%22);%0A
 %09%09%7D%0A

Fix warning