aspose file tools*
The moose likes JDBC and the fly likes Cannot insert into sql server using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Cannot insert into sql server using JDBC" Watch "Cannot insert into sql server using JDBC" New topic
Author

Cannot insert into sql server using JDBC

achuthan mukundarajan
Ranch Hand

Joined: May 30, 2012
Posts: 87
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: 16145
    
  21

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: 117
Try

executeUpdate instead of prepareCall
may be it will work
achuthan mukundarajan
Ranch Hand

Joined: May 30, 2012
Posts: 87
chain singh wrote:Try

executeUpdate instead of prepareCall
may be it will work


IT WORKED!!! thanks. Also i thank tim for the valuable advice..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot insert into sql server using JDBC