Using Mysql in Database Connectivity in Java

To connect to the database, you need to use a JDBC url with the following format

jdbc:mysql://[hostname][:port]/[dbname][?param1=value1][&param2=value2].....

This is described in the Driver documentation. Accordingly, the piece of code you must use is:

try {
                Class.forName("org.gjt.mm.mysql.Driver").newInstance();
  } catch (ClassNotFoundException cnfe)
   {
                System.err.println("Error loading driver:"+cnfe);
  }

             Connection con = DriverManager.getConnection("jdbc:mysql://localhost/Authority?user=root&password=fox123");

}

  here hostName=localhost
  dbname=Authority
  user=root
  password=fox123

Java Tips by : Karmegam

Related:

Java Books
Java Certification, Programming, JavaBean and Object Oriented Reference Books

Return to : Java Programming Hints and Tips

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.
The site www.erpgreat.com is not affiliated with or endorsed by any company listed at this site.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.