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:
[FONT="Courier New"]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page language="java" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html/ loose.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <title>GlassFish JSP Page</title>
</head>
 
<%@page import = "java.io.* " %>
<%@page import = "javax.servlet.* " %>
<%@page import = "javax.servlet.http.* " %>  
<%@page import = "java.sql.* " %> 
<%@page import = "java.util.* " %> 
<%@page import = "java.lang.Exception " %> 
 
 <body>
    <h1>Hello World...I'm new to JSP database!</h1>
         <%! 	
 
         Connection conn=null;
   	Statement st;
   	ResultSet rs;
   	try{
   	       Random rand = new Random();
	       int ch=0;
	       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	       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.");
  	       cnfs.printStackTrace();
	} catch(SQLException sqlex){
  	       System.out.println("Unable to connect.");
  	       sqlex.printStackTrace();
	} 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 ) {}
  	}
 
         %>  
   </body>
</html> 
[/FONT]


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,

MarkSquall