943,543 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 5523
  • MySQL RSS
Aug 17th, 2006
0

Accessing Mysql with Servlet.....

Expand Post »
Hi.....


How to access the MySql using servlet....
Now am using Mysql 5.0 & MyOdbc 3.51
What type of connector to be used?...
We used the following syntax..is it correct?or not?

Class.forName("org.gjt.mm.mysql.Driver");
Connection cn=DriverManager.getConnection("jdbc:mysql://192.168.1.38:3306/suba","root","erp");

Whenever i execute this program i got the error like this
ClassNotFoundException: org.gjt.mm.mysql.Driver
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
muthumari is offline Offline
20 posts
since Mar 2006
Jun 28th, 2010
0
Re: Accessing Mysql with Servlet.....
because ("com.mysql.jdbc.Driver") is a correct driver name
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dineshmca09 is offline Offline
2 posts
since Jun 2010
Jun 28th, 2010
0
Re: Accessing Mysql with Servlet.....
by dinesh trichy
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dineshmca09 is offline Offline
2 posts
since Jun 2010
Jun 28th, 2010
0
Re: Accessing Mysql with Servlet.....
Instead of using MyODBC 3.51 use MySQL JDBC Driver - mysql-connector-java-5.1.6-bin

Then use the following servlet code:

JAVA Syntax (Toggle Plain Text)
  1. import javax.swing.*;
  2. import java.sql.*;
  3.  
  4. public class Database {
  5.  
  6. private Connection connection;
  7. private static String databaseName = "";
  8. private static String databaseUsername = "";
  9. private static String databasePassword = "";
  10. private static String driver = "com.mysql.jdbc.Driver";
  11.  
  12. public Connection getConnection() {
  13. createConnection();
  14. return connection;
  15. }
  16.  
  17. public void createConnection() {
  18. if (connection == null) {
  19. try {
  20. Class.forName(driver);
  21. String url = "jdbc:mysql://localhost/" + databaseName;
  22.  
  23. connection = DriverManager.getConnection(
  24. url, databaseUsername, databasePassword);
  25.  
  26. } catch (Exception e) {
  27. JOptionPane.showMessageDialog(new JFrame(),
  28. "Database connection could not be established." +
  29. "Please check your network connection and restart.",
  30. "Error Message", JOptionPane.ERROR_MESSAGE);
  31. e.printStackTrace();
  32. connection = null;
  33. }
  34. }
  35. }
  36. }
Reputation Points: 16
Solved Threads: 17
Junior Poster
tyson.crouch is offline Offline
150 posts
since Apr 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: selecting most popular products
Next Thread in MySQL Forum Timeline: mysql query duplicate records





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC