Go Back   Java Programming Forums > Java Standard Edition Programming Help > JDBC & Databases


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-03-2010, 11:57 AM
marksquall's Avatar
Junior Member
 

Join Date: Jan 2009
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
marksquall is on a distinguished road
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" "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> 

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



Reply With Quote Share this thread on Facebook
Sponsored Links
Java Training from DevelopIntelligence
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Similar Threads
Thread Thread Starter Forum Replies Last Post
Football League Table - Idea's? RSYR Java Theory & Questions 1 15-12-2009 11:43 PM
Table locked and session was invalidated tarek.mostafa JavaServer Pages: JSP & JSTL 6 08-11-2009 08:44 AM
How to add marathi words to mysql table vaishali JavaServer Pages: JSP & JSTL 3 08-07-2009 11:43 AM
dynamic table creation jam123 JavaServer Pages: JSP & JSTL 2 08-07-2009 11:35 AM
Getting table height jsnx7 JavaServer Pages: JSP & JSTL 1 19-03-2009 04:03 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 02:07 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.