Re: DBRepository problems

Juan Carl <[email protected]> Mon, 16 Feb 2004 16:13:20 -0300 (ART)
Newsgroups gmane.comp.java.jpublish.devel
Message-ID <[email protected]>
Hi Florin,

Thanks for your help. I've tested the same example but
it doesn't work in my site :( The same problem
continues...
The exception thrown by Tomcat was:

java.lang.NullPointerException
        at
org.jpublish.repository.db.DBRepository.get(DBRepository.java:147)
        at
org.jpublish.repository.db.DBRepository.get(DBRepository.java:169)
...

I've also inspected the code from DBRepository.java at
line 147 (from public String get(String path))

Connection c = null;
        try{
            log.debug("Connecting to database.");
            c = DriverManager.getConnection(url,
username, password);
            
            PreparedStatement s =
c.prepareStatement(contentQuery);
            s.setString(1, path);
            
            log.debug("Executing query.");
            ResultSet r = s.executeQuery();
            if(r.next()){
                return r.getString(1);
            } else {
                throw new Exception("Path not found: "
+ path);
            }
        } finally {
            c.close(); //Line 147
        }
It seems the DriverManager can't establish a
connection with the database. I've tested both server
and standalone HSQLDB modes (v 1.7.1 and 1.7.2). I
think the URL string is correct. 

The db schema:

CREATE TABLE contenido (
  id_contenido	INTEGER PRIMARY KEY,
  path 		VARCHAR(255) not null,
  body		LONGVARCHAR(1000) not null,
  last_modified DATETIME not null
);

with only 1 tuple stored:

INSERT INTO Contenido VALUES(1,'/index.html',
'<p>Index page</p>', '2004-01-13 01:22:00')

I really have no ideas... :(
Thanks again for your help...

           Juan Pablo


 --- Florin PATRASCU <[email protected]> escribió: > Hi
Juan,
> 
> Please be sure the path to your hsqldb is correct.
> In my example below, 
> everything works smooth. Let us know if the example
> below was helpful. 
> Cheers - Florin
> 
> a. I am creating a sample HSQLD table and I am
> populating it with some data:
> 
> drop table CONTENIDO
> create table contenido(
>          path varchar(255) primary key,
>          data longvarchar(1000) not null,
>          LAST_MODIFIED BIGINT
> )
> select * from CONTENIDO
> INSERT INTO CONTENIDO(path,data,last_modified)
> VALUES('/index.html', 
> 'SALUD!', 2004)
> 
> 
> b. On my Windows environment,  in jpublish.xml I
> have:
>         <repository name="db_repository" 
> classname="org.jpublish.repository.db.DBRepository">
>              <driver>org.hsqldb.jdbcDriver</driver>
>             
>
<url>jdbc:hsqldb:E:\jboss\server\default\data\hypersonic\jpublish</url>
>              <username>sa</username>
>              <password></password>
>              <content-query>select data from
> contenido where path = 
> ?</content-query>
>              <last-modified-query>select
> last_modified from contenido where 
> path = ?</last-modified-query>
>              <paths-query>select * from contenido
> where path like 
> ?</paths-query>
>          </repository>
> 
> c. starting up JBOSS (I know you have TOMCAT, but it
> should work at your 
> side as well:)
> and after calling: http://localhost/jpdb/index.html
> 
> I see:
> SALUD!
> 
> ...
> 
> QED :)
> As I've said, let us now if you need more help!
> 
> -Florin
> 
> 
> 
> At 15/02/2004 20:26, you wrote:
> >Hello..
> >I'm trying to run the jpublish-example with the
> >content stored in a HSQLDB database, but I receive
> >this message (in the browser) when I try to read
> the
> >page: "Error: null".
> >It seems there isn't a problem with the SQL
> statement.
> >I think it's a problem with the connection, because
> I
> >can't see any signal from the org.hsqldb.Server
> when I
> >do the $db_repository.get($page.Path) from the
> >template. I've the hsqldb.jar in the /lib
> directory.
> >
> >This is my db configuration in the jpublish.xml
> >(similar to the jpublish-example)
> >
> ><repository name="db_repository"
>
>classname="org.jpublish.repository.db.DBRepository">
> >             <driver>org.hsqldb.jdbcDriver</driver>
> >            
> <url>jdbc:hsqldb:hsql://localhost:9001</url>
> >             <username>sa</username>
> >             <password></password>
> >             <content-query>select body from
> contenido where
> >path = ?</content-query>
> >             <last-modified-query>select
> last_modified from
> >contenido where path = ?</last-modified-query>
> >             <paths-query>select * from contenido
> where path
> >like ?</paths-query>
> >         </repository>
> >
> >
> >The table in my database is "contenido" and has the
> >same attributes I've seen in the
> jpublish-example...
> >The server is running ok, because I've connected to
> it
> >from the hsqldb DatabaseManager...
> >¿What I'm doing wrong?
> >
> >Please apologize me if it's a basic question, but I
> >need some help.
> >
> >Thanks a lot...
> >
> >           Juan Pablo
> >
> >PD: I'm using JPublish 2.0, Tomcat 4.1.24 and
> HSQLDB 1.7
> >


=====
Juan Pablo Carlino (LW4DYI)
[email protected]
Tandil - Argentina

------------
Los mejores usados y las más tentadoras 
ofertas de 0km están en Yahoo! Autos.
Comprá o vendé tu auto en
http://autos.yahoo.com.ar


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click