GeeCON Prague 2014*
The moose likes JDBC and the fly likes not able to insert values in ms access database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » JDBC
Bookmark "not able to insert values in ms access database" Watch "not able to insert values in ms access database" New topic
Author

not able to insert values in ms access database

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
Form.jsp



new2.jsp



my_ins : DNS Name
insert : Table Name





here is the code to inser values into ms access database, bt i m getting an exception here, can anyone help me in this...

exception


exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /new2.jsp at line 19

16:
17:
18: String sqlString= "Insert into insert(ID, u_name, u_post) values("+id1+",'"+nm1+"', '"+po1+"')";
19: int i=st.executeUpdate(sqlString);
20: %>
21: Record Add<%= i %><br>
22:

Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

Hey,

Include the above mentioned code in try-catch block.
Because, the Class.forName() throws ClassNotFoundException and getConnection() method throws SQLException.
These are checked Exceptions.
So, you must include the above code in try-catch bock.
Writing java code in JSP is not a good practice!!


Thanks & Regards
Gopakumar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Right. And when you catch the exception, write the stack trace to the logs so you can see what it is. Just saying "I got an exception" is not very useful. The information in the stack trace is what you need to see, including the text of the exception itself.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
Thank you all, and i have convert my jsp to servlet and also added the try catch block, it's successfully running but no data is inserted into my access database, i m using ms access 2007...
here is my servlet:



Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

This is rather typical of MS Access. Apparently if you don't close the connection, or commit the transaction, you don't see the update happening.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
i have close the connections,

st.close();
db.close();

still i m not getting the values into my database..
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

You are looking in the table named "insert", are you not? (I'm surprised that using a table named "insert" doesn't cause an SQL syntax error.)

Also, what is the value of that "i" variable?
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

Yep, sometimes this happens with MS Access.
Just checkout your DSN. Reopen MS Access ,once you execute the program.
(By the way don't use the SQL key words as table name.. it may cause some ambiguity.. rename the table if you don't mind.)
It should work.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
yes i got it, it's probably my database problem, because in my another database values are inserting.

Thank you all...
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2
i more problem i m facing, i have inserted data into database, bt while fetching the same data it displays nothing on the page, here is my servlet to fetch and display data, please help me in this also,




my login.jsp page is simply a form having two text fields and one submit....
Gopakumar Naryanan
Ranch Hand

Joined: Jan 15, 2011
Posts: 72

I had noticed the following:

DSN name is different compared to insertion & this one.
Didn't find HTML, BODY tags.
You got the data , userid.. didn't set in any scope.. how can the jsp gets these values?
Again, writing html code in java code is not a good practice.. try practicing EL with JSP.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1000
    
    2




 
GeeCON Prague 2014
 
subject: not able to insert values in ms access database