• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DWR and JdbcTemplate

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I just started with Spring and I'm trying get DWR working. Can I use a JdbcTemplate with DWR?
I set up a datasource in my applicationContext.xml but when I try and run the app it never finds the datasource. Let me know if I need to post any code, I thought maybe someone would know right away what my problem was.


Thanks
 
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Buddy,

does your JDBCTemplate (or your class that uses it) work at all?

Herman
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
Yes, it will work if I set the datasource properties myself:


Thanks for the help
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Buddy/Enoch,

Did you look at http://getahead.org/dwr/server/spring

Just define the class that you made as a "Spring bean", and this site will tell you all that you need.
Most examples will call this file applicationContext.xml

Actually: you can also define dataSource, jdbctemplate etc as "Spring beans"
instead of coding it like you did

Herman
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
So I would define my JdbcTemplate and datasource in the dwr.xml instead of the applicationContext.xml? Would it look something like this?



Thanks again
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Enoch,

First: define your Spring beans in some .xml file
(and make sure that they work without use if DWR).

Second: make them accessible to Javascript with by DWR


Herman

I'm not sure though why you want to call "JdbcTemplate" from javascript.
It's just a helper class, it does not know which SQL to execute by itself.
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
Not sure what I'm doing wrong, it's still having a problem. I put a try-catch block to see what error it was throwing, the error gets caught but the error message is always null.

Thanks
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Enoch,

probably NullPointerException then.

But where in your code, and how do you call that code.
Are all the Spring beans you defined created? (check your logs)

Herman
[ October 18, 2007: Message edited by: Herman Scheltinga ]
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Herman,
I'll post part of my code, can you take a look and see what I've done wrong.

Thanks




 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Looks OK to me, it would be a little better if HomeController was in a package.
I'll try this at home later (probably tonight).

I still don't know which line of your code throws the NullPointerException, and don't know what program you ran that caused the exception.

And did you test this code without DWR (just with Spring)?

Herman
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
It fails when it calls


I have another class I tried in Spring and it works.

Thanks for taking the trouble to look at this
 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

glad you got it working.

Can you tell us why it is working now: what's different in this other class?

Herman
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Herman,
Sorry, I guess I didn't explain it clearly. It's working in the other class with Spring because it's not using DWR it's using MVC. For what ever reason it's not seeing the DataSource or the JdbcTemplate I have defined in the config files when I use DWR.
However I added this code im my class and I'm able to get the datasource and I can run the query. Do you think that the "Context.xml" is not being loaded and that's why the DataSource is null?

 
Herman Schelti
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Enoch,

yes, I do think that Context.xml is not being loaded.

Default name for that file is applicationContext.xml, default location is in WEB-INF. If you want it differently, add to you web.xml:


Also: Spring needs commons-logging.jar (typically in WEB_INF/lib), if you want to see any logging. Without further configuration it will end-up in your console, which is fine for studying.

Like
INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [dataSource,jdbcTemplate,HomeController]; root of BeanFactory hierarchy]

Herman
 
Charles Flynn
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Herman,
I'm just going in circles with this. I added the commons-logging.jar and you were right about the NullPointerException. I can post the log if that would be helpful, or do you have a working example that you would be willing to post.

Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic