Advertisement
Guest User

Untitled

a guest
Sep 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5.  
  6. public class Main {
  7.  
  8. public static void main(String[] args) throws Exception {
  9. //Accessing driver from the JAR file
  10. Class.forName("com.mysql.jdbc.Driver");
  11.  
  12. //Creating a variable for the connection called "con"
  13. Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jedi","root", "qwert");
  14. //jdbc:mysql://localhost:3306/employee_record --> this is the database
  15. //root is the database user
  16. //qwerty is the password
  17.  
  18. //Here we create our query
  19. PreparedStatement statement = con.prepareStatement("select image from page");
  20.  
  21. //Creating a variable to execute query
  22. ResultSet result = statement.executeQuery();
  23.  
  24. while(result.next()) {
  25. System.out.println(result.getString(1));
  26. //getString returns the data
  27. //1 is the first field in the table
  28. //2 is teh second field
  29. }
  30. }
  31.  
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement