Skip to Content

JDBC Connectivity with Webdynpro and Max DB

Hello Friends,

                      My ultimate aim in this blog is to explain how to use MaxDB in Webdynpro applications, so that your webdynpro application becomes persistent with the data entered. Before starting up I would like to confirm with the pre requisites.

1.)    MaxDB installed to the server where you deploy your Webdynpro application.

2.)    SAP NWDS installed.

3.)    Check for the availability of JDBC Driver in your Visual Administrator.



Create a Dictionary Project.

Go to Dictionary Perspective-> New Project.

Enter the Project Name and click finish.

Now expand the sub tree and create a new table by right clicking on the Tables option in the Dictionary Project created. Create table rows with the data type.


Now rebuild the project, create archive. You would find the .sda archive created in the Navigator.

Now deploy your application to the J2EE Engine. Therefore the Table instance is created in the J2EE Engine.Snapshot

So the Database part is over and we shall create the Webdynpro application to access the table rows.

 Step2: Create a Webdynpro Application to Access the Database using Jdbc Connectivity

Create a Webdynpro application with views and component.

Create a context in the component controller. A Value Node with cardinality 1…n and value attributes as that of the columns which you created in the dictionary table. Bind this node to a form in the view.

Create another context in the component controller with a value node having Cardinality 0..n,  bound to a table displaying data from the database.

Use buttons which performs the action to add the data to the database remove data and retrieve data.

In the Event Handler of the button write the following code.

/* Event handler to Insert a new set of data to the Database*/

      InitialContext ctx = new InitialContext();
      java.sql.DataSource ds = (java.sql.DataSource)ctx.lookup("jdbc/DataSourceName");
                  Connection con = ds.getConnection();
                  PreparedStatement pstm = con.prepareStatement("insert into TMP_PHONEBOOK(FIRSTNAME,LASTNAME,LOCATION,MOBILENUMBER,LANDLINE,EMAIL) values(?,?,?,?,?,?)");


    catch(Exception e)
/*Event handler to Retrieve Data From The Database*/
            InitialContext ctx = new InitialContext();
            java.sql.DataSource ds = (java.sql.DataSource)ctx.lookup("jdbc/DataSourceName");
            Connection con = ds.getConnection();
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery("select * from TMP_PHONEBOOK");
                  IPrivatePhoneBookView.IOutputNodeElement ele = wdContext.createOutputNodeElement();
    catch(Exception e)
/*Event handler to Delete a particular data from the Database*/
try    {     
InitialContext ctx = new InitialContext(); 
DataSource ds = (DataSource)ctx.lookup("jdbc/DataSourceName"); 
Connection con = ds.getConnection();  
PreparedStatement stmt = con.prepareStatement("delete from TMP_PHONEBOOK where FIRSTNAME = ?"); 
} catch(Exception e)    
  Now you can rebuild your Project and deploy the application. Similarly you can use other SQL statements for required Operations. 


Please note:

1.)The DataSourceName should be obtained from the Visual Administrator.Login to the Visual Administrator. 
Go to Cluster- Server - Services - JDBC Connectors - DataSources. 

You could see the DataSource Aliases in the table..

2.) The Highlighted text in this blog denotes name of the node,attributes, table etc., which are not generic.



You must be Logged on to comment or reply to a post.
  • The practice you just shown isn’t worth implementing, because MVC pattern (Web dynpro is based on) doesn’t encourage you to write your persistence code in the view or controller, thats the responsibility of the model I guess?

    If you could write same code in the model then it has worth.

    Jawed Ali

    • Hi Jawed,
                 Thank u for the comment. Since i was just implementing the scenario, i did not code it in the component controller, which also goes against the MVC paradigm. I ve now changed the part which u mentioned.


  • Karthik,

    sorry to say that but I didn’t even read this, I stopped at the first sentence. Data handling should happen in the persistence layer of your app, not in the UI layer what Web Dynpro is (meant for).

    Don’t understand how it could appear on the SDN home page?!


  • In all fairness to Karthik, I think that the main emphasis of the blog is the correct use of JDBC with MaxDB, and [b]not[/b] a tutorial about [i]correct[/i] WD design.


    • Really? Is it?! “My ultimate aim in this blog is to explain how to use MaxDB in Webdynpro applications”
      The correct use of JDBC with MaxDB is in the DAO layer – and it certainly does not suggest root lookup of the DataSource. (took a look at the sample code after your comment)


  • Hi

    For one who is used to Java and MVC this really hurts. However, I have seen a lot of ABAP code that just goes likes this.

    To all of you WDA or ABAP programmers, please stick to your knitting and don’t try this with WDJ. Thanks.


  • * Do we need to create DataSource in Visual Admin? Can we use default one?

        * After inserting data into DataBase, how can i check inserted data? Is it with SQL Studio’s? If yes, what is the default UID for MaxDB?

        * Is there any other approach, to communicate with MaxDB and EJB/ WD?

        * If you have any good documentation please pass it to me also.

    • Hi,
      1.) You can either use the existing datasource alias or couls create a new one in the visual admin.
      2.) You can view the data inserted using SQL studio. the default user authentication should be SUPERDBA and passwd: mymaster. If this password doesn’t work contact your admin.

      Karthikeyan R