| Author |
Cannot insert into sql server using JDBC
|
achuthan mukundarajan
Ranch Hand
Joined: May 30, 2012
Posts: 31
|
|
I tried to insert into sql server using the following code:
But i get a null pointer exception. I tried printing the stack trace but i get a blank page.
Why is there a nullpointerexception? Thanks in advance.
|
 |
Tim Holloway
Saloon Keeper
Joined: Jun 25, 2001
Posts: 14467
|
|
I believe that in JSP there's a "log" object or method that will write to the server log. That will work better than attempting to log the stacktrace to the client. Or, if all else fails, write the stacktrace to System.out.
Actually, attempting to acquire a database connection in the way you described has 2 strikes against it.
1. We do not recommend putting logic in JSPs. Use the JSP for display and let a servlet do the dirty work.
2. Instead of the relatively expensive process of creating a Connection that you're using, well-written enterprise webapps use Connection Pools constructed by the webapp server.
Yes, the "brute force" ASP/PHP way is quicker to code, but J2EE is an expensive technology and the extra work up front should pay off in terms of overall maintainability and performance.
Speaking as a rabid Java fan, when I need something quick and dirty, I do use something like PHP, not J2EE.
|
Customer surveys are for companies who didn't pay proper attention to begin with.
|
 |
chain singh
Ranch Hand
Joined: Feb 28, 2012
Posts: 116
|
|
Try
executeUpdate instead of prepareCall
may be it will work
|
 |
achuthan mukundarajan
Ranch Hand
Joined: May 30, 2012
Posts: 31
|
|
chain singh wrote:Try
executeUpdate instead of prepareCall
may be it will work
IT WORKED!!! thanks. Also i thank tim for the valuable advice..
|
 |
 |
|
|
subject: Cannot insert into sql server using JDBC
|
|
|