Results 1 to 3 of 3
  1. #1
    MarkSquall's Avatar
    MarkSquall is offline Member
    Join Date
    Jul 2008
    Rep Power

    Unhappy Why the web browser needs to refresh first so that creating table may work? Pls help.

    Dear members and administrators,

    A greeeting of peace.

    I hope everyone is doing fine upon reading this thread of mine. I want to share this JSP code that I'd researched, tried and edited using Eclipse:

    Java Code:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@page language="java" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " loose.dtd">
    <html xmlns="">
         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
         <title>GlassFish JSP Page</title>
    <%@page import = "* " %>
    <%@page import = "javax.servlet.* " %>
    <%@page import = "javax.servlet.http.* " %>  
    <%@page import = "java.sql.* " %> 
    <%@page import = "java.util.* " %> 
    <%@page import = "java.lang.Exception " %> 
        <h1>Hello World...I'm new to JSP database!</h1>
             Connection conn=null;
       	Statement st;
       	ResultSet rs;
       	       Random rand = new Random();
    	       int ch=0;
    	       String file="C:\\db\\justatry.mdb";
    	       String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
        	       database += file+";DriverID=22;READONLY=true}";
                    conn = DriverManager.getConnection(database);
        	       st = conn.createStatement();
        	       st.execute("create table TEST12345 ( column_name integer )"); // create a table
            	       for (int i=0; i <=10; i++){
            	             ch = 1+rand.nextInt(20);
    	            st.execute("insert into TEST12345 values("+ ch+")"); // insert some data 
       	} catch(ClassNotFoundException cnfs){
      	       System.out.println("Failed to load JDBC/ODBC driver.");
    	} catch(SQLException sqlex){
      	       System.out.println("Unable to connect.");
    	} finally {
      	        /* try { if( null != rs ) rs.close(); } catch( Exception ex ) {} */
      	       /*  try { if( null != st ) st.close(); } catch( Exception ex ) {}  */
      	      try { if( null != conn ) conn.close(); } catch( Exception ex ) {}

    The purpose of this code is to insert a table in my MSAccess database, and store 10 random numbers in it. When I try this in the first run, it will view on my IE, but when I checked my MSAccess file, the table was not created, BUT when I go back to my IE and press F5 (refresh), and double check again my MSAccess then that is the only time my table was created and random numbers were saved. Is there a workaround in this code that if I click the "Play Button" again in my Eclipse, it (the JSP file) will automatically create my table plus saving all my random numbers in the field? Well, I hope someone could help me fix this problem.

    Thank you and more power! God bless everyone.:)

    Warm regards,


  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    First ,you should write business logic inside jsp.
    Next thing is might be ur database is open.close the ms access window and try to run the code.

  3. #3
    MarkSquall's Avatar
    MarkSquall is offline Member
    Join Date
    Jul 2008
    Rep Power

    Red face What do you meant by business logic?

    Dear RamyaSivakanth,

    Thanks for the information you gave. I always make sure that my MS Access is close before I run my JSP file, but still same result, I need to press F5 first before those date will be seen in my table. And I did not get what do you meant by business logic Sir? Is that mean an additional lines of code in my JSP file? If yes? Is there a code that I could refer to so I may study the lines?

    Thank you for replying and God bless everyone.

    Warm regards,


Similar Threads

  1. Replies: 1
    Last Post: 01-08-2010, 06:19 AM
  2. Need help creating a table
    By Knizz in forum SWT / JFace
    Replies: 3
    Last Post: 07-18-2009, 03:46 AM
  3. Creating a SWT table with 1,000,000 items
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 04:31 PM
  4. Replies: 4
    Last Post: 01-05-2008, 07:39 PM
  5. regarding to creating table.....
    By daredavil82 in forum New To Java
    Replies: 0
    Last Post: 11-18-2007, 04:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts