cancel
Showing results for 
Search instead for 
Did you mean: 

Portal's db custom usage?

Former Member
0 Kudos

Hello,

Is it possible to use portal's db to store any data that my

application might require? Is there any APIs at the portal

that allow to work with portal's db (create tables/add records/

remove/update)? If not, where and how my own portal application

can manage all the required data?

Thank you,

Yuri

Accepted Solutions (0)

Answers (1)

Answers (1)

achim_hauck2
Active Contributor
0 Kudos

you're free to access the portal-db via jdbc and use the db for your data.

before you should create a new schema/user with db-tools.

there's no special api in my knowledge, you have to code it hard in jdbc and/or access your data via a jdbc-connector.

kr, achim

Former Member
0 Kudos

I think you should be able to use the portal database schema by using a standard JNDI lookup.

The best way to do this is to

1. define a new datasource in the dbpool service in the SAP J2EE administration console.

2. Call it using a standard JNDI call (you might need a reference to a service in your component)

I can see if I can find some more details on this

Former Member
0 Kudos

Hi,

That standard JNDI call (btw, what did you mean by a

"reference to a service in your component"?) can be

used from the portal component? Let me ask it this

way - will it allow me to create an iview that uses

it to access the datasource and run some SQL queries?

It looks like there four possible ways to establish

a jdbc connection:

1. The one you suggested (if it fits my needs).

2. To define it as JDBC Connection Pool through system

administration -> km -> configuration -> cm -> utilities

-> jdbc connection pools (in case the portal provides an

API to work with those objects).

3. To create JDBC System and then JDBC iView and to try

to customize it somehow, if possible.

4. To customize JdbcConnectionExample.java provided with

the PDK.

I beleive the benefit of the first two methods is that

they provide an always-open connection when 3 and 4

open connection for each request. Their downside is

that I do not know yet how to work with them.

What would be your suggestion?

Thank you,

Yuri

Former Member
0 Kudos

Hi Yuri,

With "reference to a service in your component" i meant that you portal component might need a sharing reference to a portal service. This is defined in the portalapp.xml.

This will allow you to get a pooled connection from the J2EE connection pool which you can do standard JDBC calls on.

I promise I will find out more by tomorrow

Former Member
0 Kudos

Okei,

This document describes everything you need to know :

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/Use%20SAP...

The code given in this pdf is (with some modifications, could do a lot of compacation in order to increase readability)


public Connection getConnection () {
 InitialContext m_ctx = null;
 DataSource m_ds = null;
 //note  LocalPool is the pool Alias.
 String m_datasource_name = "jdbc/LocalPool"; 
 String m_contextUrl = "";
 String m_contextFactory 
  = "com.inqmy.services.jndi.InitialContextFactoryImpl";
 Connection con;
 Properties properties = new Properties();
 properties.put  (InitialContext.INITIAL_CONTEXT_FACTORY,m_contextFactory);
 try{
  //getting JNDI InitialContext
  m_ctx = new InitialContext(properties);
  //getting the Datasource from the context
  m_ds = (DataSource)m_ctx.lookup(m_datasource_name);
  //getting the connection from the Datasource
  con = m_ds.getConnection();
  return con;
 }catch (NamingException ne){
  //pool not created in J2EE. Handle this in someway
  ne.printStackTrace();
  return null;
 }catch (SQLException sqle){
  //could not get connection from database
  //perhaps database is down or J2EE pool points
  //to wrong database url
  sqle.printStackTrace();
  return null;
 }catch (Exception e){
   //some other exception might happen (don't 
   //think you need this
   e.printStackTrace();
   return null;
}
}

Former Member
0 Kudos

Hi Dagfinn,

Two more questions:

1. The "How To..." doc is for EP5, but the admin side

looks exactly like in EP6, the question is whether all

the classes used in sample code are good for EP6 as well

(I am very suspicious for this one, for example -

com.inqmy.services.jndi.InitialContextFactoryImpl)?

2. Why I still have to take jar files from server to

be able to run the sample (jdbc20.jar for DataSource

class for example)? Shouldn't Eclipse plug-ins and

portallibs (downloadable through PDK) contain all I

need?

Thank you,

Yuri

Former Member
0 Kudos

1. It is the same for EP6.

The name inqmy is the original name of the J2EE engine SAP bought some years ago and it is still visible in a lot of the apis

2. It ought to be, but the portallibs was a quickfix for a defect in the PDK, and the jdbc20.jar was probably not thought of at the time. If you would like, you could send an email to sdn@sap.com and ask if they could include it.

Former Member
0 Kudos

1. Thanks.

2. I just wanted to be sure that I don't miss anything.