Advertisement
Guest User

Untitled

a guest
Aug 5th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. public class JDBC{
  4. Connection con;
  5. String s1;
  6. String s2;
  7. String s3;
  8. String st="";
  9.  
  10. public static void main(String[] args){
  11. JDBC j1 = new JDBC();
  12.  
  13. }
  14. public String getR(){
  15. return st;
  16. }
  17.  
  18. public JDBC(){
  19. try {
  20. Class.forName("com.mysql.jdbc.Driver");
  21. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/activity","root","");
  22. Statement stmt = con.createStatement();
  23. ResultSet rst = stmt.executeQuery("SELECT * FROM sample");
  24.  
  25. while (rst.next()){
  26. s1 = rst.getString(1);
  27. s2 = rst.getString(2);
  28. s3 = rst.getString(3);
  29. st += s1+s2+s3;
  30.  
  31. System.out.println(s1 + " " + s2 + " " + s3);
  32. }
  33. }
  34. catch(Exception e){
  35. System.out.println(e);
  36.  
  37. }
  38. /*finally{
  39. try{
  40. con.close();
  41. }
  42. catch (Exception e){
  43. }
  44. }*/
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement