Skip to Content

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

"UnknownHost" exception while connecting to mysql from web dynpro

Hi

I am trying to connect to Mysql 5.0 database from web dynpro application.I am using NWDS 7.1.

I have followed this blog and created the datasource in NWA.

https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/8675

I have written the following code in my web dynpro application.

InitialContext ctx;
	  try{
		  ctx=new InitialContext();
		  DataSource ds=(DataSource)ctx.lookup("jdbc/dbconnect");
		  Connection conn=ds.getConnection();	
		  wdComponentAPI.getMessageManager().reportSuccess("connected");
		  Statement stmt=conn.createStatement();
			String query="select Col from TestTable";
			ResultSet res=stmt.executeQuery(query);
			while(res.next())
			{
				String str1=res.getString(1);
				wdComponentAPI.getMessageManager().reportSuccess(str1);
			}
		  
		  
	     }catch (Exception e) {
	    	 wdComponentAPI.getMessageManager().reportSuccess(e.getMessage());
			// TODO: handle exception
		}

But I m getting the following error as "UnknownHost exception"

I checked with the datasource created in NWA.Here in the Driver status it is showing the driver as unknown.

I have added the following driver.

mysql-connector-java-5.0.8-bin.jar

Any idea on how to solve this problem?

Do I need to add the driver in my application also.

Thanks in advance,

Sumangala

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