Re: Big Crash
Posted by: E M
Date: February 25, 2005 01:36AM

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);
		}	
	}

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
Re: Big Crash
E M
February 25, 2005 01:36AM
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.