Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connecting to a server

 
Nirmala Dhara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am new to struts and I want to create a web interface to my database application. Once I login, I need to conncet to my server and it should be available to all my action classes. Where should I create connection to my database server? and How?

Thank you very much,
Nirmala
 
Stefan Evans
Bartender
Posts: 1778
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should set up a JNDI datasource.
Most applications servers will do that for you.
Here is the link for the Tomcat docs: http://jakarta.apache.org/tomcat/tomcat-5.5-doc/jndi-datasource-examples-howto.html

Also, Struts purists will insist that your action should not contain any connections to a database. That responsibility belongs to another layer.
Check out the
Data Access Object pattern
 
Nirmala Dhara
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also need to connect to backend server on Nonstop platform. From logon screen I get IP and port for it. Should I use JNDI for this type connection?

Thanks
Nirmala
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic