Re: Big Crash
Posted by: Mark Matthews
Date: February 25, 2005 11:04AM

E M wrote:
> Ok. Is this the way to do it? I could could not
> find a Connection.reconnect(), so I had to create
> a new one through the DriverManager. Will my
> PreparedStatements using that connection need to
> be recreated or will they still be intact? In the
> finally I closed the connection like you suggested
> and refreshed it. Is that ok?
>
>
>
> // my connection properties
> private String dbUrl;
> private String dbUser;
> private String dbPassword;
> // my connection
> private Connection con;
>
>
> private PreparedStatement pstmtSelect;
> public ResultSet selectClient(int id){
> try {
> // make sure connection is refreshed
> refresh();
> // make SELECT
> pstmtSelect.clearParameters() ;
> pstmtSelect.setInt(1,id);
> return pstmtSelect.executeQuery();
> }catch(Exception e){
> System.out.println("Select failed:"+e);
> }finally{
> // close and re-open connection
> con.close();
> refresh();
> }
> }
>
> public void refresh(){
> if(con.isClosed()){
> con=DriverManager.getConnection( dbUrl,
> dbUser, dbPassword);
> }
> }
>


E M,

Connection.isClosed() isn't going to help you much. Take a look at the following section from the docs that shows one possible way of doing this...Also, note that in most applications, you probably don't want to be using DriverManager, as it has static synchronization issues...If you're only using MySQL, just use an instance of com.mysql.jdbc.Driver and call the .connect() method to get a new connection:

http://dev.mysql.com/doc/connector/j/en/cj-troubleshooting.html#id2629885

-Mark

Mark Matthews
Consulting Member Technical Staff - MySQL Enterprise Tools
Oracle
http://www.mysql.com/products/enterprise/monitor.html

Options: ReplyQuote


Subject
Written By
Posted
E M
February 24, 2005 10:04AM
E M
February 24, 2005 11:23AM
February 24, 2005 02:19PM
February 24, 2005 02:33PM
February 24, 2005 05:34PM
E M
February 25, 2005 01:36AM
Re: Big Crash
February 25, 2005 11:04AM
E M
February 25, 2005 11:51PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.