cancel
Showing results for 
Search instead for 
Did you mean: 

connection to database

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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