on 01-11-2010 11:28 AM
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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.