Ktilis

Untitled

Dec 18th, 2020 (edited)
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. package ru.ktilis.warps;
  2.  
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.SQLException;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8.  
  9. import com.mysql.jdbc.Connection;
  10. import com.mysql.jdbc.Statement;
  11.  
  12. public class DatabazeSQL {
  13. private String user;
  14. private String password;
  15. private String url;
  16.  
  17. public DatabazeSQL() throws Exception {
  18. user = "";
  19. password = "";
  20. url = "jdbc:mysql://" + "" + ":" + "" + "/" + "";
  21. Class.forName("com.mysql.jdbc.Driver").newInstance();
  22.  
  23.  
  24. }
  25.  
  26. public Connection getConnection() throws SQLException {
  27. if(user != null) {
  28. return (Connection) DriverManager.getConnection(url, user, password);
  29. } else {return (Connection) DriverManager.getConnection(url);}
  30. }
  31.  
  32. public void saveData(String name, int x, int y, int z, float yaw, float pitch) {
  33. try {
  34. Connection c = getConnection();
  35. Statement s = (Statement) c.createStatement();
  36.  
  37. s.executeUpdate("INSERT INTO warps (`name`,`x`,`y`,`z`,`yaw`,`pitch`) VAULES (`" + name + "`,`" + x + "`,`" + y + "`,`" + z + "`,`" + yaw + "`,`" + pitch + "`);");
  38.  
  39. s.close();
  40. c.close();
  41. } catch (Exception e) {
  42. e.printStackTrace();
  43. }
  44. }
  45.  
  46. @SuppressWarnings({ "rawtypes", "unchecked" })
  47. public List getData(String name) {
  48. List list = new ArrayList<>();
  49. try {
  50. Connection c = getConnection();
  51. Statement s = (Statement) c.createStatement();
  52.  
  53. ResultSet res = s.executeQuery("SELECT `name`,`x`,`y`,`z`,`yaw`,`pitch` FROM warps WHERE `name`='" + name + "'");
  54.  
  55. list.add(res.getString("name"));
  56. list.add(res.getInt("x"));
  57. list.add(res.getInt("y"));
  58. list.add(res.getInt("z"));
  59. list.add(res.getFloat("yaw"));
  60. list.add(res.getFloat("pitch"));
  61.  
  62.  
  63.  
  64. s.close();
  65. c.close();
  66. } catch (Exception e) {
  67. e.printStackTrace();
  68. }
  69. return list;
  70. }
  71.  
  72. public void removeData(String name) {
  73. try {
  74. Connection c = getConnection();
  75. Statement s = (Statement) c.createStatement();
  76.  
  77. s.executeUpdate(String.format("DELETE FROM warps WHERE `name`='%s'", name));
  78.  
  79. s.close();
  80. c.close();
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. }
  84. }
  85. }
  86.  
Add Comment
Please, Sign In to add comment