www.pudn.com > 33_online_store.rar > BuildDB.java


package shopcart;

import java.sql.*;

public class BuildDB
{
	public static void main(String[] args)
	{
        String url = null;
        String user=null;
        String password=null;
        String driver=null;
		Connection conn;
		Statement statement;
		ResultSet rs;
		
		int i,max;
		String data[][] = {{"CG-100 Introduction to CGI with Perl","895","12","0"}
							,{"NS-101 Introduction to JavaScript","895","0","0"}
							,{"JV-220 Programming Java","1995","1","0"}
							,{"CGI How-To","39.99","1","0"}
							,{"Programming With JFC","49.99","10","0"}
							,{"Perl 5 How-To","49.99","0","0"}};
							
		String customers[][] = {{"stephen","2000","0"}
							    ,{"scott","2000","0"}
							    ,{"joe","100","50"}};
					
		try
		{	
    
            if ((args != null) && (args.length > 1)) 
            {
                for (i = 0; i < args.length; i++)
                {
                    if (args[i].equals("-url")) 
                        url = args[++i];
                    else if (args[i].equals("-driver")) 
                        driver = args[++i];
                    else if (args[i].equals("-user")) 
                        user = args[++i];
                    else if (args[i].equals("-password")) 
                        password = args[++i];
                }
            }
            
            if((url == null)||(driver == null))
            {
                System.out.println("usage: BuildDB"
                                    +" -url url"
                                    +" -driver driverClassName"
                                    +" [-user user]"
                                    +" [-password pass]");
                                    
                System.exit(0);
            }
			
			//Cache the driver
			Class.forName(driver);
			
			conn = DriverManager.getConnection(url,user,password);
			
			statement = conn.createStatement();
			
			try
			{
				statement.executeUpdate("drop table INVENTORY");
			}
			catch(SQLException exp)
			{
				System.out.println("Already dropped INVENTORY");
			}
			
			statement.executeUpdate("create table INVENTORY "
						            +"(ITEM_DESC varchar(64), "
						            +"PRICE float, "
						            +"QUANTITY int, "
						            +"SALES int)");
			
			max = data.length;
			
			for(i=0;i