• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to execute multiple sql commands on a database simultaneously...?

 
Abhijit Kangale
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want to execute multiple sql commands in a single program. But one command is a "select" and another is a "insert". Next thing is that both commands uses different tables of same database. How can I do this task.... I tried it using batch but is not working. Below is my trial code..


Can anyone please tell me where I m committing mistake....? Suggestions are welcome...
Regards,
Abhijit
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to use Threads if you want to process simultaneously.

JDBCSupport is a good start for your SQL interaction.
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Abhijit ,

Putting JDBC code in JSP pages is not reccommended. I would like to advise you not to do that.
Attempting to multi-thread JDBC inside a JSP page is even more daring.
Such complex logic does not belong in JSP.

Regards, Jan
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Very true.

If you want to process things simultaneously, you will eventually have to go multi threaded, but not in a JSP.

That code belongs into a Servlet or other class outside the presentation layer.
 
Abhijit Kangale
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiiii Jan ,

How can I achieve this task...? please suggest me something...?

Regards,
Abhijit
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remove all scriptlets out of your JSP, because they don't belong there.

If you decide to check out JDBCSupport import it as a library and in your servlet do the transactions.

This is the easiest way, usually you would modularize much more.
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abhijit Kangale wrote:Hiiii Jan ,

How can I achieve this task...? please suggest me something...?

Regards,
Abhijit


Abhijit,

you should only keep display (=presentation) logic in the jsp page. Anything else *belongs somewhere else* .
There is an article on the server side that is more then 10 years old, but it does explain the concept, and gives you something you can try yourself. Please also read our faq on this topic.


On running queries in parallel:
I would first check if I really need to do that. If you have performance issues, please find out what is causing them, before designing a fix.
Performance issues have the tendency not to be caused by what you think they are caused by (what a sentence).
Your sql seems to be simple. Are they giving you performance issues?

If you need to run the queries in parallel, you will have to learn about multi-threading in java, and about creating thread-safe JDBC code.

Regards, Jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic