Guest User

Untitled

a guest
Sep 16th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. No suitable driver found for jdbc mysql?
  2. import java.sql.*;
  3.  
  4. public class FirstExample {
  5.  
  6. //static final String S_JDBC_DRIVER = "com.mysql.jdbc.Driver";
  7. static final String S_DB_URL = "jdbc:mysql://localhost:3306/emp";
  8. static final String S_USER = "root";
  9. static final String S_PASS = "root";
  10.  
  11. public static void main(String[] args) {
  12.  
  13. try {
  14.  
  15. System.out.println("Connecting to database...");
  16. //Class.forName(S_JDBC_DRIVER);
  17. Connection connection = DriverManager.getConnection(S_DB_URL,
  18. S_USER, S_PASS);
  19.  
  20. System.out.println("Creating statement...");
  21. Statement statement = connection.createStatement();
  22. String sql = "SELECT * FROM Employee";
  23. ResultSet resultSet = statement.executeQuery(sql);
  24.  
  25. while (resultSet.next()) {
  26.  
  27. int iId = resultSet.getInt("id");
  28. int iAge = resultSet.getInt("age");
  29. String sFirst = resultSet.getString("fname");
  30. String sLast = resultSet.getString("lname");
  31.  
  32. System.out.print("ID: " + iId);
  33. System.out.print("tAge: " + iAge);
  34. System.out.print("tFirst: " + sFirst);
  35. System.out.println("tLast: " + sLast);
  36. }
  37.  
  38. resultSet.close();
  39. statement.close();
  40. connection.close();
  41. } catch (SQLException se) {
  42.  
  43. for (Throwable t : se) {
  44. t.printStackTrace();
  45. }
  46. }
  47. System.out.println("Goodbye!");
  48. }
  49.  
  50. Connecting to database...
  51. java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/emp
  52. at java.sql.DriverManager.getConnection(Unknown Source)
  53. at java.sql.DriverManager.getConnection(Unknown Source)
  54. at FirstExample.main(FirstExample.java:21)
  55. Goodbye!
Add Comment
Please, Sign In to add comment