• 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

connection to database with struts

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello all,
I have some problem in conncting with the database using struts application
please tell me how to connect for ms-access databse,
where to include that (jdbc dbc:Jdbcodbc) bridge ,where to include dsn.
iam confused please help me.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
look you can access the database by entering this code in struts-config.xml
below is the code to enter
<data-sources>
<data-source
type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="driverClassName"
value="com.mysql.jdbc.Driver" />
<set-property property="url"
value="jdbc:mysql://localhost/retail" />
<set-property property="username"
value="root" />
<set-property property="password"
value="root" />
</data-source>
</data-sources>
in the place of driverclassName put your jdbc dbc bridge and on the url place put the database name with the required things.

and now in the action class you can use this.

DataSource dataSource=getDataSource(HttpServletRequest);
Connection con=dataSource.getConnection() and now the rest things are as usual...
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd advise against using the Struts DataSource configuration utility. It's deprecated in later versions, so it would make your application more difficult to upgrade. It also has portability issues. I've seen instances where it worked fine in development, but didn't work when the application was ported to production.

The best practice for connecting to a JDBC DataSource in a Struts or any J2EE Web Application is to define the DataSource as a JNDI resource using your Application Server's preferred method and then using JNDI to look up the DataSource in your application code. If you're using Tomcat, this link explains how to do it.

Also see question 7 in the JavaRanch Struts FAQ.
[ March 20, 2007: Message edited by: Merrill Higginson ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic