• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Code to connect database with struts using MyEclipse

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hellow friends,

I am using struts with Myeclipse 6.0

I want the code for connecting to the databse using Datasource object.

Please help me.
I am waiting for replay.

Thank you,
Krishna.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Krishna,
use the code inside your strutsconfig.xml
i.e.
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource" key="jdbc/struts">
<set-property property="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<set-property property="url" value="jdbc:sqlserver://localhost:1433;Database=Databasename" />
<set-property property="username" value="xx" />
<set-property property="password" value="xxxxxx" />
<set-property property="validationQuery" value="SELECT * FROM Table name" />
</data-source>
</data-sources>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With all respect to Jagan, it is best if you do not use the Struts DataSource. It has been removed in later versions, so you limit your upgrade options by using it.

The best practice for data sources in Struts applications as in all Java EE applications is to use the Application Server's utilities for setting up a data source that is registered in the Java Naming and Directory Interface (JNDI) and then using JNDI to look up the data source in your code. For more information on this, see question 8 of this forum's FAQ.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic