Foren

How to call an oracle database with a portlet?

thumbnail
Erik Forsström, geändert vor 14 Jahren.

How to call an oracle database with a portlet?

Junior Member Beiträge: 59 Beitrittsdatum: 25.03.10 Neueste Beiträge
Hello.

I'm still extremely new to Liferay and I'm trying to understand the "simple" stuff. I'm trying to create a new very simple portlet, that searches a database for rows. But I am stumped right at the beginning since I can't get anywhere.

I am using Liferay 5.2.3 and Oracle database. Liferays data itself is running on the Oracle so I did get the portal itself working with that database.

But now I'm trying to connect to a different database with a portlet.

So far the code inside view.jsp of my portlet looks like this (comments and such removed):


<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineobjects />
&lt;%@ page import="oracle.jdbc.driver.OracleDriver" %&gt;

&lt;%	
  DriverManager.registerDriver(new OracleDriver()); 
  con = DriverManager.getConnection("jdbc:oracle:thin:@ora9i:1521:KU9A", "login", "password");
  out.println(con);
%&gt;


I deploy the portlet with Ant, but the portlet is "not available." The tomcat window returns a HUGE error log with one telling line, that says "An error occurred at line: 36 in the jsp file: /view.jsp
DriverManager cannot be resolved

I've got the ojdbc14.jar in the tomcat/lib directory and importing the oracle.jdbc.driver.OracleDriver seems to work fine. So why can't this thing resolve the DriverManager. I must be missing something really basic here.

Any help would be greatly appreciated. Thank you!
thumbnail
Erik Forsström, geändert vor 14 Jahren.

RE: How to call an oracle database with a portlet?

Junior Member Beiträge: 59 Beitrittsdatum: 25.03.10 Neueste Beiträge
Right. Looks like I'm going this the wrong way from the start. I'll take a look at connection pools...
Juan Antonio Gálvez Jiménez, geändert vor 14 Jahren.

RE: How to call an oracle database with a portlet?

Junior Member Beiträge: 42 Beitrittsdatum: 19.11.09 Neueste Beiträge
Hi Erik, when I have used oracle db in portlets I have needed driver version 10.2.0.4. It`s not the driver version Liferay uses (not the same .jar file).


get luck.
John Malick, geändert vor 13 Jahren.

RE: How to call an oracle database with a portlet?

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Everyone,

HELP!!!! I am very new to LIFERAY and JAVA programming. I have been asked to develop a simple portlet in Eclipse and deploy it to a LIFERAY portal on my PC. I was asked to download LIFERAY 6.0 version to my PC (free version) and create an portlet using Eclipse. The portlet is suppose to connect to an Oracle database and just retrieve records from the database to display. I believe I know how to write the portlet (but any help would be appreciated) but I am not sure how to connect to the Oracle database. Is that done through LIFERAY itself. Do I add something to my portlet code (like the view.jsp) above? Can someone show me how to do this. I need help!!! Thanks in advance. Have a good day.
John Malick
thumbnail
Patrick NERDEN, geändert vor 13 Jahren.

RE: How to call an oracle database with a portlet?

New Member Beiträge: 10 Beitrittsdatum: 16.04.10 Neueste Beiträge
Hi John,

On an architectural point of view, a portlet is a view to your business application (the UI). You must never put any business intelligence inside a portlet out of the simple UI intelligence.

What you shall do is :

- Create a web application with a DAO layer which accesses your database and a service layer that uses this DAO for business purposes. Do this with whatever framework you want (Spring, home made POJOs, ...)
- Write a technical interface to access your service layer (Web Services, JAVA classes you'll use with a JAR client, ...). In this technical interface, you will design functions that can be directly called by your UI with a data model that suits your needs (we call this model a DTO).

Then, create a simple portlet that will call your technical interface layer to access services.

By developping this way, you can quickly assemble a business application that suits your needs with as many portlets as you like to display data inside a browser. There's absolutely no benefit in using Liferay as a Framework. But using it's power for assembling portlets to draw custom ergonomic dashboards is awesome.

Patrick.
John Malick, geändert vor 13 Jahren.

RE: How to call an oracle database with a portlet?

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Patrick,

Thank you for the reply. Since I am very new at this, I am not sure exactly what you are saying so I will explain exactly what I have done so far.

I am using Eclipse IDE to develop the portlet. I am using Hiberate for the DAO/TO classes. I have also written my service layer. I create a simple JSP page with one simple connect to my Oracle database to retrieve a list of values (using the service class I created). A simple pull down list. I am using SpringFrame to pull things together. When I deploy my portlet (WAR file) to LIFERAY that was installed on PC (using Tomcat as my application server) I keep getting the error message "Name jdbc is not bound in this Context". Can you please tell me what this message means. I thought I had it defined in a file I created called portlet-servelt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd" default-autowire="byName">

<context:annotation-config />
<context:component-scan base-package="edu.fccc.psf" />

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
scope="singleton">
<property name="jndiName" value="java:comp/env/jdbc/portlets" />
<property name="resourceRef" value="false" />
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<value>edu.fccc.psf.projecttasks.to</value>
<value>edu.fccc.psf.projecttasks.dao</value>
<value>edu.fccc.psf.projecttasks.portlet</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_second_level_cache">
true
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.jdbc.batch_versioned_data">
true
</prop>
</props>
</property>
</bean>

<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<tx:annotation-driven proxy-target-class="true" />


<bean id="defaultExceptionHandler" class="org.springframework.web.portlet.handler.SimpleMappingExceptionResolver">
<property name="order" value="10"/>
<property name="defaultErrorView" value="error"/>
<property name="exceptionMappings" >
<props>
<prop key="javax.portlet.PortletSecurityException">unauthorized</prop>
<prop key="javax.portlet.UnavailableException">unavailable</prop>
</props>
</property>
</bean>
</beans>

Am I making any sense? Sorry, if I am not. Thanks in advance. Have a good day.

John Malick
thumbnail
jelmer kuperus, geändert vor 13 Jahren.

RE: How to call an oracle database with a portlet?

Liferay Legend Beiträge: 1191 Beitrittsdatum: 10.03.10 Neueste Beiträge
You are using jndi to look up the datasource and it cannot find the datasource by the name you specified ("java:comp/env/jdbc/portlets")

1. make sure you configured your application server so that a datasource is actually being shared
2. if you are sure about 1 try setting jndiName to "jdbc/portlets" instead of "java:comp/env/jdbc/portlets"

Btw if you include the jee namespace you can use this shorthand form to reference a jndi object

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/portlets" />
John Malick, geändert vor 13 Jahren.

RE: How to call an oracle database with a portlet?

New Member Beiträge: 21 Beitrittsdatum: 14.09.10 Neueste Beiträge
Hello Jelmer,

I am developing the portlet on my PC, not on a server so I tried your second suggestion and it did not work.

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean"
scope="singleton">
<property name="jndiName" value="jdbc/portlets" />
<property name="resourceRef" value="false" />
</bean>

It still can not find my data source. Any suggestions? Have a good day.

John Malick