cancel
Showing results for 
Search instead for 
Did you mean: 

Mysql datasource and WebDynpro

Former Member
0 Kudos

Hello all!

I'm new at WD and NW features and I'm trying to figure out the best way to access an external Mysql database with webdynpro.

I already configured an external mysql datasource at NW CE and it's working fine.

My doubt is about how I'm going to access this datasource in NWDS? Do I need to create a new Dictionary? How does it work? How do I link this datasource with my WebDynpro project?

And about the persistence? Must I use JPA, EJB? How do I do it?

Is there any article about this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

there are already a lot of examples in the forum of how to connect MySql db with the portal.

Here is a simple solution:

If you have already created a datasource:

try {

InitialContext initialContext = new InitialContext();

DataSource dataSource = (DataSource)initialContext.lookup("jdbc/YOUR_DB_ALIAS");

connection= dataSource.getConnection();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (NamingException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

And you must change YOUR_DB_ALIAS with the real alias name. That is all if you have already created a datasource.

About what to use: you can use whatever you want. This is just a simple example of how to get your db connection. After that you can do whatever you want with it.

You can write your one db engine if you want:

PreparedStatement stmt = connection.prepareStatement("insert into simple_table simple_values(?)");

stmt.setString(1, "Hello world");

stmt.execute();

Or you can use JPA, JDO, EJB, etc... It depends only on your decision. All of them will work.

Former Member
0 Kudos

Thank you man.

That is really what I was looking for. I'll try to implement JPA + DAO.

Answers (0)