Skip to Content
avatar image
Former Member

How to query a sql database table from webdynpro?

Hi All,

Can someone tell me the steps involved in accessing a sql server database table and retrieving the record set from a webdynpro application.

Thanks in advance.

Best regards,

Divya

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 06, 2005 at 03:40 PM
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Dec 06, 2005 at 04:01 PM

    Hi Divya,

    here is a code sample that may help you (SAPTT3DB is the name of the DataSource. In my case,SAP<SID>DB. You can find this in the Visual Administrator):

    ResultSet rs;

    boolean found=false;

    try {

    InitialContext ctx = new InitialContext();

    javax.sql.DataSource ds =

    (javax.sql.DataSource) ctx.lookup("jdbc/SAPTT3DB");

    java.sql.Connection con = ds.getConnection();

    java.sql.Statement stmt = con.createStatement();

    rs = stmt.executeQuery("SELECT * FROM DEMO_FP where NUMERO="+num);

    while (rs.next()){

    found=true;

    wdContext.currentFichePrixElement().setCodeAch(rs.getString("CODE_ACH"));

    [...]

    }

    con.close();

    }

    catch(Exception e){

    msgMgr.reportException(e.getMessage(),true);

    }

    Best Regards,

    Julien

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Divya,

      Create a node with the required attributes.

      In the left hand side where the project structure is being shown right click on the view and choose "Apply Template" .

      Choose the "table" and then the attributes you want to display in table

      Write this code in the implementation

      IPrivate<view name>.I<node name>Element element;

      While(rs.next())

      {

      element = wdContext.node<node name>.create<node name>element();

      element.setDataField1(rs.getString("Test1"));

      element.setDataField2(rs.getString("Test2"));

      wdContext.node<node name>.addelement(element);

      }

      Hope this helps you

      Regards

      Rohit