cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting Database from WebDynpro

Former Member
0 Kudos

Hello experts,

i`ve created a table from my NWDS and deploed it.

The table is based on following Columns:

- id

- Username

- password

- description

- furtherinformation

Now I want to connect from my WebDynproProject to this Database. Is there a step by step Documentation/Tutorial availiable.

Many Thanks!

Edited by: Marco Gennari on Oct 14, 2008 12:38 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

for accesing the database u can also follow process.

1. first create a DSN in VA.

2. For getting a connection write a code in java class.

3. in your controller access the method and get connection.

4. once connection is established u can easily access alla the values from database.

for any code and clarification reply.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Following thread gives you some hints

Regards

Ayyapparaj

Former Member
0 Kudos

First of all - thank you for your quick answers.

I have now implemented folowing code im my wdDoInit:

"DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@Oracle_server_ip:Oracle port:SID of the Database","user_name","password");

Statement stmt = conn.createStatement();

ResultSet rs = stmt.executeQuery("your query");"

The problem is that we are using a MaxDB Database. Is that OracleDriver compatibel???

Another Issue are the imports?

Which imports are necessary for

- Connection

- DriverManager

- Statement

.....

Many Thanks

marco

Former Member
0 Kudos

Hi,

right click on the statement and use the organize imports option.

Former Member
0 Kudos

Hi,

The problem is that we are using a MaxDB Database. Is that OracleDriver compatibel???

No, You need to get the driver for MAX DB

Link for download and sample class

http://www.sapdb.org/sap_db_jdbc.htm

Another Issue are the imports?

Which imports are necessary for

Connection

DriverManager

Statement

All the above are part of jdbc api (java.sql. ).

Regards

Ayyapparaj

Former Member
0 Kudos

I have implemented the Connection as following but I Get following exception:

!!!!Object not found in lookup of SAPMJ2DB.!!!

Any ideas?

public void wdDoInit()

{

//@@begin wdDoInit()

try{

InitialContext ictx = new InitialContext();

DataSource dsc = (DataSource)ictx.lookup("jdbc/SAP""MJ2""DB");

Connection conn = dsc.getConnection();

String sqlStr = ("Select * FROM Test_Users");

Statement Stmt = conn.createStatement();

ResultSet rs = Stmt.executeQuery(sqlStr);

//as ResultSet in deinen Context schreiben

conn.close();

}catch(NamingException nex){

IWDMessageManager manager = wdComponentAPI.getMessageManager();

manager.reportException(nex.getMessage(),false);

}catch(SQLException sqlEx){

IWDMessageManager manager2 = wdComponentAPI.getMessageManager();

manager2.reportException("nx.getMessage,false);

}

//@@end

}

Former Member
0 Kudos

Hi,

DataSource dsc = (DataSource)ictx.lookup("jdbc/SAP""MJ2""DB");

Have you created a datasource of the above name using visual administrator?

Regards

Ayyapparaj

Former Member
0 Kudos

No, is this necessary?

I thought I give him a url and it will find the Table. Hmmm, it seems it is not easy as I thought.

Could you explain how i configure a datasource step by step?

Regards

Marco

Former Member
0 Kudos

Hi,

No, is this necessary?

Yes if you are accessing it using DataSource

Other option is

String url = "jdbc:sapdb://" + host + "/" + dbname; // replacec host and dbname with yours

Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");

Connection connection = DriverManager.getConnection (url, user, password);

Regards

Ayyapparaj

Former Member
0 Kudos

Thank you very much.

But now I get a classexception like

!!com.sap.dbtech.jdbc.DriverSapDB!!

I have importe following packages:

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import com.sap.dbtech.jdbc.DriverSapDB;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import mhp.com.portal.userlist.wdp.IPrivateTestUser

import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;

Is there maybe a conflict so that DriverSapDb is not working???

Thanks

Former Member
0 Kudos

Hi,

add the driver jar file to your application build path.

Regards

Ayyapparaj

Former Member
0 Kudos

I have already downloaded the jar file of JDBC Driver and added it like. right-click on project->properties->addExternalJar->sapdbc.jar

But the exception still appears?

Any ideas?

Thanks a lot?

Former Member
0 Kudos

Hi,

Could you please post the entire exception?

Regards

Ayyapparaj

Former Member
0 Kudos

Sure.

Exeption:

com.sap.dbtech.jdbc.DriverSapDB

Source Code:

imports:

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import mhp.com.portal.userlist.wdp.IPrivateTestUser;

import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;

public void wdDoInit()

{

//@@begin wdDoInit()

try{

Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");

InitialContext ictx = new InitialContext();

String host = "xxxxxxxxx";

String dbname ="Test_Useres";

String url = "jdbc:sapdb://" + "localhost"+ "/" + "Test_Users";

java.sql.Connection conn =java.sql.DriverManager.getConnection (

"jdbc:sapdb://" + host + "/" + dbname);

String sqlStr = ("Select * FROM Test_Users");

Statement Stmt = conn.createStatement();

ResultSet rs = Stmt.executeQuery(sqlStr);

//as ResultSet in deinen Context schreiben

conn.close();

}catch(NamingException nex){

IWDMessageManager manager = wdComponentAPI.getMessageManager();

manager.reportException(nex.getMessage(),false);

}catch(SQLException sqlEx){

IWDMessageManager manager2 = wdComponentAPI.getMessageManager();

manager2.reportException(sqlEx.getMessage(),false);

}

catch(ClassNotFoundException classEx){

IWDMessageManager manager2 = wdComponentAPI.getMessageManager();

manager2.reportException("classexception"+classEx.getMessage(),false);

}

Edited by: Marco Gennari on Jan 20, 2009 5:10 PM

Former Member
0 Kudos

hi,

Create an external library type project and put your jar in that project under jar folder.Expose your jar via public parts.

Now in your database web dynpro DC,add this new DC in dependency.

Hope this hould work!!

Bye

Former Member
0 Kudos

Hi Macro

Please go through this forums link Hope u will find ur answer

Regards

Ruturaj

former_member192434
Active Contributor
0 Kudos

Hi Marco,

just check this link

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8041f93c-8e76-2b10-d5b9-862ed014...

thank

Edited by: Anup Bharti on Oct 14, 2008 12:48 PM

Former Member
0 Kudos

Hi,

may be this helpful to you,

Reading and Writing Images from SQLServer in WebDynpro

Regards,

ramesh