Guest User

Untitled

a guest
Nov 27th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. package raizel;
  2.  
  3.  
  4. import java.sql.*;
  5. public class ConnectToDB
  6. {
  7.  
  8. public boolean add(String name, String username, String password)
  9. {
  10. String url = "jdbc:mysql://localhost/practice";
  11. String userid = "root";
  12. String pass = "root";
  13.  
  14. try {
  15. Class.forName("com.mysql.jdbc.Driver");
  16. }
  17. catch(java.lang.ClassNotFoundException e)
  18. { System.err.print("ClassNotFoundException: " + e.getMessage()); }
  19.  
  20.  
  21. try
  22. {
  23. Connection con = DriverManager.getConnection(url, userid, pass);
  24. Statement stmt;
  25. stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  26. stmt.executeUpdate("Insert into account (name,username,password) values('"+name+"','"+username+"','"+password+"')");
  27. stmt.close();
  28. con.close();
  29. }
  30. catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); return false;}
  31. return true;
  32. }
  33.  
  34. /*public String [] browse(String passToBrowse)
  35. {
  36.  
  37. String returnValue[] = new String[3];
  38. String url = "jdbc:mysql://10.4.195.241/ceacwed";
  39. String userid = "ceacwed";
  40. String pass = "miyerkules";
  41.  
  42. System.out.println(userid +" "+pass);
  43. try { Class.forName("com.mysql.jdbc.Driver"); }
  44. catch(java.lang.ClassNotFoundException e) { System.err.print("ClassNotFoundException: " + e.getMessage()); }
  45.  
  46.  
  47. try
  48. {
  49. Connection con = DriverManager.getConnection(url, userid, pass);
  50. Statement stmt;
  51. stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
  52. ResultSet rs = stmt.executeQuery("Select username from account where password = '"+passToBrowse+"'");
  53. rs.next();
  54. returnValue[0] = rs.getString("password");
  55. // returnValue[1] = rs.getString("address");
  56. // returnValue[2] = rs.getString("telephone");
  57. stmt.close();
  58. con.close();
  59. }
  60. catch(SQLException ex) { System.err.println("SQLException: " + ex.getMessage()); }
  61. return returnValue;
  62.  
  63. }*/
  64.  
  65.  
  66. }
Add Comment
Please, Sign In to add comment