It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes mySql connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "mySql connection" Watch "mySql connection" New topic

mySql connection

Joseph Bashir
Ranch Hand

Joined: Jun 16, 2004
Posts: 41
Can someone please tell me how to connect to mysql database?

Ben Souther

Joined: Dec 11, 2004
Posts: 13410

From a web app?
If so, what container are you using?

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Nimish Patel
Ranch Hand

Joined: Jun 29, 2005
Posts: 84

if you use tomcate 5.5.x version ,u have to configure in context.xml
otherwise in server.xml.

download mysql driver from net.
driver name like this "mysql-connector-java-3.0.16-ga-bin.jar"

copy this file in %CATALINA_HOME%\common\lib folder.

and following code in context.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Context crossContext="true" debug="5" docBase="/xyz" path="/xyz" reloadable="true">
<Resource auth="Container" driverClassName="" factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory" logAbandoned="true" maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/abc" password="admin" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource" url="jdbc:mysql://localhost:3306/databasename?autoReconnect=true" username="root" />

change name,pathname and username,databasename relative to u.ok
if u changes according to ur application, i hope it will works.

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Moving this to the JDBC forum. This forum is for Servlets questions.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
I agree. Here's the link:
subject: mySql connection
It's not a secret anymore!