Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

jdbc in Webdynpro

Hi,

I'm using the following code

  public void wdDoInit()
  {
    //@@begin wdDoInit()
	try {		
		ConnectDB("dsource");
		String sqlQuery = "Select * from myTable";
		if (wdThis.wdGetContext().currentContextElement().getConn().isClosed()) {
			msgMgr.reportWarning("Connection Closed");
			return;
		}
		
		LoadData(selectQuery(sqlQuery));
	}
	catch (NamingException e) {
		msgMgr.reportException("ERROR - NamingException in wdDoInit - " + e.getLocalizedMessage(), true);
	}
	catch (SQLException e) {
		msgMgr.reportException("ERROR - SQLException in wdDoInit - " + e.getLocalizedMessage(), true);
	}
	catch (ClassNotFoundException e) {
		msgMgr.reportException("ERROR - ClassNotFoundException in wdDoInit - " + e.getLocalizedMessage(), true);
	}
	catch (Exception e) {
		msgMgr.reportException("ERROR - Exception in wdDoInit - " + e.getLocalizedMessage(), true);
	}			

  public void ConnectDB(String dataSource) throws NamingException, SQLException, ClassNotFoundException, Exception {
	  InitialContext ctx = new InitialContext();
	  DataSource ds = (DataSource) ctx.lookup("jdbc/" + dataSource);
	  wdThis.wdGetContext().currentContextElement().setConn(ds.getConnection());
  }

  public ResultSet selectQuery(String Sqlstring) throws SQLException {
	  Statement ps = wdThis.wdGetContext().currentContextElement().getConn().createStatement();
	  return ps.executeQuery(Sqlstring);
  }

In the selectQuery function I get the following error -

<i>SQLException - The connection is closed.</i>

What is wrong here?

Former Member
Not what you were looking for? View more on this topic or Ask a question