Helo experts,
I'm working on my first ever web application and I have some basic questions related to servlets if I may,
I have 5-6 Java statements and preparedstateme nts in my servlet to execute a number of MySQL queries for different tables, do I need to open a new connection to the database for each query or can I just create one connection and use it for all the queries?
Also, if I'm using a preparedstateme nt and resultset for a particular query, then after closing them both can I again reuse them for another query in the same piece of code or is it better to create a new statement/preparedstateme nt object for every different query and close all the resultsets and statements etc in the end of the doGet()/doPost() method?
I've been told to not declare a preparedstateme nt or a statement as global since that has something to do with multithreading, hence I create and use them in the doPost() or doGet(). What is the reason behind not declaring them as global if that program is going to be accessed by multiple users? Is it because the global copy will be shared by all or something else?
Does opening multiple connections on a database in the same program and using many statements/preparedstateme nts affect the performance in any way?
Why is it a good practice to close all the opened connections in destroy()? Will they still remain open even if the user closes the browser window(webpage) to which this servlet is linked?
I'm working on my first ever web application and I have some basic questions related to servlets if I may,
I have 5-6 Java statements and preparedstateme nts in my servlet to execute a number of MySQL queries for different tables, do I need to open a new connection to the database for each query or can I just create one connection and use it for all the queries?
Also, if I'm using a preparedstateme nt and resultset for a particular query, then after closing them both can I again reuse them for another query in the same piece of code or is it better to create a new statement/preparedstateme nt object for every different query and close all the resultsets and statements etc in the end of the doGet()/doPost() method?
I've been told to not declare a preparedstateme nt or a statement as global since that has something to do with multithreading, hence I create and use them in the doPost() or doGet(). What is the reason behind not declaring them as global if that program is going to be accessed by multiple users? Is it because the global copy will be shared by all or something else?
Does opening multiple connections on a database in the same program and using many statements/preparedstateme nts affect the performance in any way?
Why is it a good practice to close all the opened connections in destroy()? Will they still remain open even if the user closes the browser window(webpage) to which this servlet is linked?
Comment