Results 1 to 3 of 3
- 03-04-2010, 10:10 AM #1
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
- 03-04-2010, 10:18 AM #2
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.Ramya:cool:
- 03-29-2010, 11:14 AM #3
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,
MarkSquall
Similar Threads
-
How to repaint.refresh the table (table model) with combo box selection envent
By man4ish in forum AWT / SwingReplies: 1Last Post: 01-08-2010, 06:19 AM -
Need help creating a table
By Knizz in forum SWT / JFaceReplies: 3Last Post: 07-18-2009, 03:46 AM -
Creating a SWT table with 1,000,000 items
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:31 PM -
how to refresh the table when a new account is added and display instantly
By sravanthi narra in forum SWT / JFaceReplies: 4Last Post: 01-05-2008, 07:39 PM -
regarding to creating table.....
By daredavil82 in forum New To JavaReplies: 0Last Post: 11-18-2007, 04:55 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks