Foren

Liferay 6 portlet datasource

Sebastian Monte, geändert vor 13 Jahren.

Liferay 6 portlet datasource

New Member Beiträge: 20 Beitrittsdatum: 20.07.10 Neueste Beiträge
Hey again,

I would like my portlet to connect to another database using datasource. Here is my set up (followed this tutorial)

In tomcat/conf/context.xml

	<resource name="jdbc/MyDbPool" auth="Container" type="javax.sql.DataSource" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:mysql://localhost/osse?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" username="**" password="**" maxActive="20" />


And I connect using

Connection con = null;
		try {
			container = new TagContainer();
			javax.naming.InitialContext ctx = null;
			try {
				ctx = new javax.naming.InitialContext();
				javax.sql.DataSource ds = null;
				ds = (javax.sql.DataSource) ctx
						.lookup("java:comp/env/jdbc/MyDbPool");
				con = ds.getConnection();

			} catch (NamingException e) {
				e.printStackTrace();
			}



However, this gives me an error


javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
	at org.apache.naming.NamingContext.lookup(NamingContext.java:770)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:140)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:781)
	at org.apache.naming.NamingContext.lookup(NamingContext.java:153)
	at org.apache.naming.SelectorContext.lookup(SelectorContext.java:152)
	at javax.naming.InitialContext.lookup(InitialContext.java:392)
	at com.example.tagmanagement.TagContainer.createWithData(TagContainer.java:34)
	at com.example.tagmanagement.TagManagementApplication.getDataSource(TagManagementApplication.java:92)
...


It seems that Liferay overwrites the context.xml file and my <Resource> elements gets wiped. What can I do?

Thanks!
thumbnail
Nagendra Kumar Busam, geändert vor 13 Jahren.

RE: Liferay 6 portlet datasource

Liferay Master Beiträge: 678 Beitrittsdatum: 07.07.09 Neueste Beiträge
Hi Sebastian,

I hope you need to change driverClassName as below

<resource name="jdbc/MyDbPool" auth="Container" type="javax.sql.DataSource" driverClassName="[color=#DC1B1B]com.mysql.jdbc.Driver[/color]" url="jdbc:mysql://localhost/osse?useUnicode=true&amp;characterEncoding=UTF-8&amp;useFastDateParsing=false" username="**" password="**" maxActive="20" />




jTDS is an open source 100% pure Java (type 4) JDBC 3.0 driver for Microsoft SQL Server (6.5, 7, 2000, 2005 and 2008) and Sybase (10, 11, 12, 15)


Please inform whether it is working or not

Regards,
- Nagendra Kumar
Sebastian Monte, geändert vor 13 Jahren.

RE: Liferay 6 portlet datasource

New Member Beiträge: 20 Beitrittsdatum: 20.07.10 Neueste Beiträge
Hey, unfortunately that was not the problem. I accidentally pasted the wrong driver information..