You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Ken <ki...@gmail.com> on 2008/11/12 07:19:40 UTC

[T5] How to connect DB on Tapestry

Hi, list.

I'm using Tapestry 5.0.15.

I wrote a bit of code:

  String driver = "org.postgresql.Driver";
  String url = "jdbc:postgresql://localhost/sample";
  String username = "hoge";
  String password = "hogo";

  Properties properties = new Properties();
  properties.put(Context.INITIAL_CONTEXT_FACTORY, driver);

  Context context = new InitialContext(properties);
  DataSource ds = (DataSource)context.lookup(url);
  Connection con = ds.getConnection(username, password);

in my service class, and got an exception:

  javax.naming.NoInitialContextException: Cannot instantiate class:
org.postgresql.Driver [Root exception is java.lang.ClassCastException:
org.postgresql.Driver]

How do I let it work to?


On struts & Tomcat, we can use META-INF/context.xml
and just write:

  Context ctx = new InitialContext();
  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/sample");

How do I write on Tapestry? (or Jetty???)

Thanks.

Ken.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] How to connect DB on Tapestry

Posted by Ken <ki...@gmail.com>.
Hi,

I downloaded latest Jetty, and Exception was gone.
Sorry. It is not a Tapestry issue.

Ken.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] How to connect DB on Tapestry

Posted by Ken <ki...@gmail.com>.
Hi, again.

I wrote "jetty-web.xml" and put it into src/main/webapp/WEB-INF/.
When I run jetty with Eclipse plug-in, I've got an error below.

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" 
"http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
	<New id="sample" class="org.mortbay.jetty.plus.naming.Resource">
		<Arg></Arg>
		<Arg>jdbc/sample</Arg>
		<Arg>
			<New class="org.postgresql.ds.PGConnectionPoolDataSource">
				<Set name="User">hoge</Set>
				<Set name="Password">hogo</Set>
				<Set name="DatabaseName">sample</Set>
				<Set name="ServerName">localhost</Set>
				<Set name="PortNumber">5432</Set>
			</New>
		</Arg>
	</New>
</Configure>

java.lang.ClassNotFoundException: org.mortbay.jetty.webapp.WebAppContext

I think I need org.mortbay.jetty.webapp.WebAppContext, but I cannot
found it.
Does somebody tell me where it is, please?

I'm using Jetty 6.1-SNAPSHOT on Eclipse.

thanks,
Ken.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] How to connect DB on Tapestry

Posted by Ken <ki...@gmail.com>.
Hello Renat,

Thanks for the reply.

> You are mixing two things here. One is JDBC and how to use it
> directly. Another one is JNDI and how to find JDBC data source inside
> JNDI (in case it's configured there).

Yes. I exactry confused.
The latter is that I want, ... I suppose.

> And about JNDI you can have a look here:
> 
> http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html for Tomcat
> http://docs.codehaus.org/display/JETTY/JNDI for Jetty

Thank you for your advice!
I try to read it.

Ken.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: [T5] How to connect DB on Tapestry

Posted by Renat Zubairov <re...@gmail.com>.
Hello Ken,

You are mixing two things here. One is JDBC and how to use it
directly. Another one is JNDI and how to find JDBC data source inside
JNDI (in case it's configured there).

Neither of both topics are anyhow related to Tapestry. I would suggest
you to look for the answers elswhere, for example here:

http://java.sun.com/docs/books/tutorial/jdbc/basics/connecting.html

And about JNDI you can have a look here:

http://tomcat.apache.org/tomcat-5.5-doc/jndi-resources-howto.html for Tomcat
http://docs.codehaus.org/display/JETTY/JNDI for Jetty

BR
Renat

2008/11/12 Ken <ki...@gmail.com>:
> Hi, list.
>
> I'm using Tapestry 5.0.15.
>
> I wrote a bit of code:
>
>  String driver = "org.postgresql.Driver";
>  String url = "jdbc:postgresql://localhost/sample";
>  String username = "hoge";
>  String password = "hogo";
>
>  Properties properties = new Properties();
>  properties.put(Context.INITIAL_CONTEXT_FACTORY, driver);
>
>  Context context = new InitialContext(properties);
>  DataSource ds = (DataSource)context.lookup(url);
>  Connection con = ds.getConnection(username, password);
>
> in my service class, and got an exception:
>
>  javax.naming.NoInitialContextException: Cannot instantiate class:
> org.postgresql.Driver [Root exception is java.lang.ClassCastException:
> org.postgresql.Driver]
>
> How do I let it work to?
>
>
> On struts & Tomcat, we can use META-INF/context.xml
> and just write:
>
>  Context ctx = new InitialContext();
>  DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/sample");
>
> How do I write on Tapestry? (or Jetty???)
>
> Thanks.
>
> Ken.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Best regards,
Renat Zubairov

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org