Advertisement
Guest User

Untitled

a guest
Aug 28th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. DBConnect connect = new DBConnect();
  6. connect.getData();
  7. }
  8.  
  9. }
  10.  
  11. import java.sql.*;
  12.  
  13.  
  14. public class DBConnect {
  15.  
  16.  
  17.  
  18. private Connection con;
  19. private Statement st;
  20. private ResultSet rs;
  21.  
  22. public DBConnect(){
  23. try{
  24.  
  25. Class.forName("com.mysql.jdbc.Driver");
  26.  
  27.  
  28. con = DriverManager.getConnection("jdbc:mysql://localhost:8080/software","root","usbw");
  29.  
  30. st = con.createStatement();
  31.  
  32.  
  33. }catch(Exception ex){
  34.  
  35. System.out.println("Error:" + ex);
  36.  
  37. }
  38.  
  39.  
  40. }
  41.  
  42. public void getData(){
  43.  
  44. try{
  45.  
  46. String query="select from * football";
  47.  
  48. rs = st.executeQuery(query);
  49.  
  50. System.out.print("Records from the database");
  51.  
  52. while(rs.next()){
  53. String name = rs.getString("Name");
  54.  
  55. System.out.print("Name: "+name+" ");
  56. }
  57. }catch(Exception ex){
  58. System.out.println(ex);
  59. }
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement