/** reads csv file and creates MySQL db on the local machine. flags: -f filename -d dimensions -s|-i all data treated as strings or integers output: db table filled with csv data (attrs and measure) for count diamonds the measure column is initialized to zero written by Hazel Webb February 5, 2009 **/ import java.sql.*; import java.util.*; public class DBsqlPreprocessor{ private static int d; //number of data dims private static int MEASURE_INDEX; //location of the measure value (final field in each line of data) private static boolean v = false; //noisy output private static String file; //store input file name private static boolean integers = false; //all data will be treated as integers (except measure it will always be double) private static boolean strings = false; //all data will be treated as strings (except measure it will always be double) private static boolean indexes = false; //default:no indexes will be created, if true every column will get an index private static Connection con; private static Statement stmt; private static Statement countStmt; static ResultSet rs; //use stack to track attrs to be deleted static Stack toDelete; static Stack dateToDelete; static String table; private static String type; private final static int MAXCHARS = 30;//for size of varchar private static String tablename; private static String connectString = "jdbc:mysql://localhost/YOUR-DATABASE-NAME"; private static String user = "XXX";//use your user name private static String pwd = "XXX";//your password //default connection can be overridden by cmd line connection string public static void main(String[] args){ DBsqlPreprocessor proc = new DBsqlPreprocessor(); Hashtable hashFlags = new Hashtable(); //hardcode maps from flag strings to integers hashFlags.put("-filename", new Integer(0)); hashFlags.put("-f", new Integer(0)); hashFlags.put("-d", new Integer(1)); hashFlags.put("-i", new Integer(2)); hashFlags.put("-s", new Integer(3)); hashFlags.put("-h", new Integer(4)); hashFlags.put("-v", new Integer(5)); hashFlags.put("-c", new Integer(6)); hashFlags.put("-u", new Integer(7)); hashFlags.put("-p", new Integer(8)); hashFlags.put("-index", new Integer(9)); if(args.length < 5){ System.out.println("Usage: DBsqlPreprocessor -f filename -d dims -i OR -s [-v verbose -c connectString -u user -p password -index]"); System.exit(1); } int iarg; for(int a=0;a