Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting multiple rows at a time in the table?

 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to insert multiple rows into a table.What i have is an ArrayList of unique ids.On the basis of that ids i am exceuting the insert queries.

I am able to insert some rows but after some time the class starts throwing exception :The exception message i got in my class is:

Exception while executing executeUpdate() preparedStatement in updateExecute()java.lang.NullPointerException.

So how to do this thing??
[ July 01, 2006: Message edited by: Bear Bibeault ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jignesh,
Can you post the code that is setting up the prepared statement and parameters? This will help someone give you a more useful response.
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne ,

Here is the code u asked for:

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jignesh,
Note that if multiple clients are using the same instance of this class, it will cause problems as the PreparedStatement instance variable is shared. Is that the case here?
 
Jignesh Gohel
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes but its a web application & with every request a new thread will start.Actually Tomcat container will handle the threading issues(Correct me if i am wrong).
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jignesh Gohel:

//moDbConn is the Connection class object (an instance variable)


public boolean createPreparedStatement(String query,HashMap params,int queryType,HttpServletRequest request)



First of all, you should declare data access logic in some dao but not in Servlet. They are just controllers.

Second, don't declare any instance variables. They are shared resource. Declare them locally within method.

Third, if you have used a separate dao for data access, then don't pass request or response to your dao components. Its a bad design. You are restricting your dao for only http access.

What if some other client like thin client want to access your dao. You can't resue same code. You have to rewrite your dao for mobile clients.

Simple rule is don't expose your servlet things outside servlet.


Regards


Naseem
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic