How to connect data source for mysql in tomcat server

Questions by naggeek

Showing Answers 1 - 12 of 12 Answers

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;
        }
       
    }

  Was this answer useful?  Yes

tinakhanna

  • May 27th, 2009
 

class.forName("sun.jdbc.odbcjdbcdriver");
Connection con=Drivermanager.getConnection("Jdbc:odbc:Databasename","userid","password");

  Was this answer useful?  Yes

masarrat

  • Jul 2nd, 2009
 

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");

  Was this answer useful?  Yes

dhayasinfo

  • Dec 3rd, 2009
 

We can configure the database connection by setting the connectino atributes in server.xml file which is available in conf folder in the tomcat home path. In this server.xml file there is an tag attributes related make connection pool for any database. For my sql you have to specifiy the my sql driver details and user name, password details and place the mysql_connector.jar file in the lib folder.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions