wood burning stoves 2.0*
The moose likes JDBC and the fly likes Inserting multiple rows at a time in  the table? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Inserting multiple rows at a time in  the table?" Watch "Inserting multiple rows at a time in  the table?" New topic
Author

Inserting multiple rows at a time in the table?

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
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 ]

Regards,
Jignesh

The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276
Hi Jeanne ,

Here is the code u asked for:

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30050
    
149

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

Joined: Dec 28, 2004
Posts: 276
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

Joined: Apr 25, 2005
Posts: 809

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


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inserting multiple rows at a time in the table?
 
Similar Threads
DB2 duplicate rows error code
JDBC Connection successful but havin problems with the SQL Statements in java now :(
JDBC & JSP
multiple rows problem
How to insert record into multiple table uesing preparedStatement (one time i want to insert record)