Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cannot insert into sql server using JDBC

 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18152
52
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chain singh
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try

executeUpdate instead of prepareCall
may be it will work
 
achuthan mukundarajan
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
chain singh wrote:Try

executeUpdate instead of prepareCall
may be it will work


IT WORKED!!! thanks. Also i thank tim for the valuable advice..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic