I am receiving a data from the socket. My ServerSocket creats a new thread for each new request. Then a need to upload the data to MySQL database. A database connection and all required prepared statemnts were created beforehand.
Well, I want to process all requests at the same time. Is that mean, that I need several connections to the database? I was considering pooled connections, but prepared statemens must be created only one time at application startup.
What is the best way to implement that to achive the best performance?
What if I replace my database with Oracle. Should I use several connections? Tom Kyte in the first chapter of his book appeals to use only one connection to the Oracle database, while MS SQLServer is used with several ones. Does it mean, that I can execute several statements using only one connection?
You need pool of connection with cached connections for more details you can see http://en.wikipedia.org/wiki/Connection_pool. You can have cached prepared statements and after each execute clear parameters.
For best performance you need use Thread pool also not need create a new thread for each new request.
I think you can create some pool of prepared statements , and retrieving those by some key (you can define keys for queries).
Something like that :