Skip to Content
author's profile photo Former Member
Former Member

connection to database

hai to everyone

i have issue with database coonection

we have default jbdbc source how to acces the data from it

in java webdynpro,how to give the url part correctly there

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 12:52 PM

    Hi

    for connecting to backend database in NWDS

    Use this code

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

    String url="jdbc:sapdb://<HostID>/J2E?sqlmode=ORACLE";

    Connection con=DriverManager.getConnection(url,"SAPJ2EDB","admin");

    Then Write the code for Executing query

    Regards

    LakshmiNarayana

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 30, 2007 at 02:05 PM

    Shravan,

    There's nothing specific to Web Dynpro here; just straight Java / JDBC. The example code below is for Oracle. Of course, if you want the connect to the backend R/3 database, the usual caveats and warnings about "going behind R/3's back" apply. RFC, web services, etc. are a better method for interfacing to an R/3 DB.

    1. Load the driver, e.g., for Oracle:

    Class.forName("oracle.jdbc.driver.OracleDriver");

    2. Construct the URL for your database, e.g.,

    String dbUrl = "jdbc:oracle:thin:@" + host + ":" + port + ":" + database;

    e.g.,

    String dbUrl = "jdbc:oracle:thin:@server.ip.address.com:1527:youDB";

    3. Get a connection

    Connection con = DriverManager.getConnection (dbUrl, userName, password);
    

    4. Create a Statement

    Statement stmt = con.createStatement();
    

    5. Execute query

    Result resultSet = stmt.executeQuery (query);
    

    6. Close the result set, statement and connection in reverse order.

    Good luck,

    Kelly

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.