Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. package com.example.portlet;
  2.  
  3. import java.sql.*;
  4. public class Test {
  5. public static void main(String[] args) {
  6. try {
  7. Class.forName("com.mysql.jdbc.Driver");
  8. } catch(ClassNotFoundException e) {
  9. System.out.println("Class not found "+ e);
  10. }
  11. System.out.println("JDBC Class found");
  12. int no_of_rows = 0;
  13.  
  14. try {
  15. Connection con = DriverManager.getConnection (
  16. "jdbc:mysql://localhost/odpadki","root", "Cuftek!234");
  17. Statement stmt = con.createStatement();
  18. ResultSet rs = stmt.executeQuery ("SELECT * FROM mapa");
  19. while (rs.next()) {
  20. no_of_rows++;
  21. }
  22. System.out.println("There are "+ no_of_rows + " record in the table");
  23. } catch(SQLException e){
  24. System.out.println("SQL exception occured" + e);
  25. }
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement