0

I'm using JSF XHTMLwith beans but I'm trying to implement a scanner with SQL to so I can create a table using input from a user and that will be displayed on the XHTML page using fields shown the the pictures just need help to implement them.

public static void createDbTable() throws SQLException {
            PreparedStatement stmt = null;
        ResultSet rs = null;
        Connection con = null;  

        String dbTableName;
        String nameResult;
        String prodName;
        int prodPrice;
        String prodMark;


        **Trying to use scanner for user input strings ready for database**
        Scanner kybd = new Scanner(System.in);
        System.out.println("Please Enter a Database Table Name with no spaces: ");
        dbTableName = kybd.next();
        System.out.println("The name you entered is: "+ dbTableName);
        kybd.nextLine();

        System.out.println("Please Enter a Store Name: ");
        nameResult = kybd.next();
        System.out.println("The name you entered is: "+ nameResult);
        kybd.nextLine();

        System.out.println("Please Enter a Product Name: ");
        prodName = kybd.next();
        System.out.println("The name you entered is: "+ prodName);
        kybd.nextLine();

        System.out.println("Please Enter a Product Price: ");
        prodPrice = kybd.nextInt();
        System.out.println("The name you entered is: "+ prodPrice);
        kybd.nextLine();

        System.out.println("Please Enter a Product Mark: i.e. YKIU: ");
        prodMark = kybd.next();
        System.out.println("The name you entered is: "+ prodMark);
        kybd.nextLine();

I'm trying to let the user name the fields so they can name the database and the fields to show on XHTML

enter image description here

        String createTableSQL = "CREATE TABLE" + dbTableName 
                +"("+ nameResult+"VARCHAR(20) NOT NULL, "
                +"("+ prodName +"VARCHAR(20) NOT NULL, "  
                +"("+ prodPrice+"INTEGER NOT NULL, "
                +"("+ prodMark+ "VARCHAR(20) NOT NULL, "
                + "PRODUCT_ID INTEGER PRIMARY KEY, UNIQUE, "
                + "CREATED_BY VARCHAR(20) NOT NULL, "
                + "CREATED_DATE DATE NOT NULL, "+ ")";
        try {
            stmt = con.prepareStatement(createTableSQL);
            System.out.println(createTableSQL);
            stmt.execute(createTableSQL);
            System.out.println("Table "+ dbTableName +" is created!");

        } 
        catch (SQLException e) 
        {
            System.out.println(e.getMessage());
        } 
        finally 
        {
            if (stmt != null)
            {
                stmt.close();
            }enter code here
            if (con != null) 
            {
                con.close();
            }
        }
    }

im trying to link the page through xhtml

enter image description here

Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76

0 Answers0