Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 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. import java.sql.SQLException;
  6.  
  7.  
  8.  
  9. public class db {
  10. public String result;
  11. public String request (String col, String nick) throws SQLException {
  12.  
  13.  
  14. String url = "jdbc:mysql://localhost:3306/JavaRot";
  15. // Access driver from jar file.
  16. try {
  17. Class.forName("com.mysql.jdbc.Driver");
  18. } catch (ClassNotFoundException e1) {
  19. // TODO insert error msgs.
  20. e1.printStackTrace();
  21. }
  22. Connection con = DriverManager.getConnection(url,"JavaRot", "M@H4jr");
  23.  
  24. // Query creation.
  25. //db dbObject = new db("SELECT hosts FROM users_GTAnet WHERE nick = '" + sender + "'");
  26. try{PreparedStatement statement = con.prepareStatement("SELECT " + col + " FROM users_GTAnet WHERE nick = '" + nick + "'");
  27.  
  28. // Set var to exec query.
  29. ResultSet rs = statement.executeQuery();
  30. // Fetch each row from the result set
  31. while (rs.next()) {
  32.  
  33. // Get the data from the row using the column name
  34. result = rs.getString(col);
  35.  
  36.  
  37. }
  38.  
  39.  
  40. }catch (SQLException e) {}
  41. public String result;
  42. return result;
  43.  
  44.  
  45.  
  46.  
  47.  
  48. }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement