fork download
  1. //STEP 1. Import required packages
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.SQLException;
  5. import java.sql.Statement;
  6.  
  7. class JDBCExample {
  8. static final String DB_URL = "jdbc:mysql://localhost/TUTORIALSPOINT";
  9. static final String USER = "guest";
  10. static final String PASS = "guest123";
  11.  
  12. public static void main(String[] args) {
  13. // Open a connection
  14. try(Connection conn = DriverManager.getConnection(DB_URL, USER, PASS);
  15. Statement stmt = conn.createStatement();
  16. ) {
  17. // Execute a query
  18. System.out.println("Inserting records into the table...");
  19. String sql = "INSERT INTO Registration VALUES (100, 'Zara', 'Ali', 18)";
  20. stmt.executeUpdate(sql);
  21. sql = "INSERT INTO Registration VALUES (101, 'Mahnaz', 'Fatma', 25)";
  22. stmt.executeUpdate(sql);
  23. sql = "INSERT INTO Registration VALUES (102, 'Zaid', 'Khan', 30)";
  24. stmt.executeUpdate(sql);
  25. sql = "INSERT INTO Registration VALUES(103, 'Sumit', 'Mittal', 28)";
  26. stmt.executeUpdate(sql);
  27. System.out.println("Inserted records into the table...");
  28. } catch (SQLException e) {
  29. e.printStackTrace();
  30. }
  31. }
  32. }
Success #stdin #stdout #stderr 0.16s 60616KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/TUTORIALSPOINT
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:702)
	at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:228)
	at JDBCExample.main(Main.java:14)