GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Struts
Go To First  |  Previous Question  |  Next Question 
 Struts  |  Question 100 of 103    Print  
How to connect data source for mysql in tomcat server

  
Total Answers and Comments: 3 Last Update: July 02, 2009     Asked by: naggeek 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 16, 2008 03:08:17   #1  
nguoitinhcuasong Member Since: August 2007   Contribution: 1    

RE: How to connect data source for mysql in tomcat server
You can nonnect to mysql datasource without tomcat server by folowing way:

- Setup mysql
-download mysql connector(driver) and add file .jar to your project
-run mysql create datasource
- Write code to connect to that datasource:

public static Connection getConnection(){


try{
Connection conn DriverManager.getConnection("jdbc:mysql://127.0.0.1/lamtung?user root&password vertrigo");
return conn;
}
catch(SQLException se)
{
se.printStackTrace();
return null;
}

}

 
Is this answer useful? Yes | No
May 27, 2009 07:31:21   #2  
tinakhanna Member Since: May 2008   Contribution: 1    

RE: How to connect data source for mysql in tomcat server
class.forName("sun.jdbc.odbcjdbcdriver");
Connection con Drivermanager.getConnection("Jdbc:odbc:Databasename" "userid" "password");

 
Is this answer useful? Yes | No
July 02, 2009 09:45:09   #3  
masarrat Member Since: July 2006   Contribution: 9    

RE: How to connect data source for mysql in tomcat server
First download mysql.jar and mysql connector then load the driver

Class.forName("com.mysql.jdbc.Driver");

then create a database in mysql lets assuse "test" is the database name. for using mysql we must provide user name and password while obtaining connection. here we assume "root" is username and password as well. so the code will be

Connection con DriverManager.getConnection("mysql://localhost:3306/test" "root" "root");

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape