Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.ktilis.warps;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import com.mysql.jdbc.Connection;
- import com.mysql.jdbc.Statement;
- public class DatabazeSQL {
- private String user;
- private String password;
- private String url;
- public DatabazeSQL() throws Exception {
- user = "";
- password = "";
- url = "jdbc:mysql://" + "" + ":" + "" + "/" + "";
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- }
- public Connection getConnection() throws SQLException {
- if(user != null) {
- return (Connection) DriverManager.getConnection(url, user, password);
- } else {return (Connection) DriverManager.getConnection(url);}
- }
- public void saveData(String name, int x, int y, int z, float yaw, float pitch) {
- try {
- Connection c = getConnection();
- Statement s = (Statement) c.createStatement();
- s.executeUpdate("INSERT INTO warps (`name`,`x`,`y`,`z`,`yaw`,`pitch`) VAULES (`" + name + "`,`" + x + "`,`" + y + "`,`" + z + "`,`" + yaw + "`,`" + pitch + "`);");
- s.close();
- c.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public List getData(String name) {
- List list = new ArrayList<>();
- try {
- Connection c = getConnection();
- Statement s = (Statement) c.createStatement();
- ResultSet res = s.executeQuery("SELECT `name`,`x`,`y`,`z`,`yaw`,`pitch` FROM warps WHERE `name`='" + name + "'");
- list.add(res.getString("name"));
- list.add(res.getInt("x"));
- list.add(res.getInt("y"));
- list.add(res.getInt("z"));
- list.add(res.getFloat("yaw"));
- list.add(res.getFloat("pitch"));
- s.close();
- c.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- public void removeData(String name) {
- try {
- Connection c = getConnection();
- Statement s = (Statement) c.createStatement();
- s.executeUpdate(String.format("DELETE FROM warps WHERE `name`='%s'", name));
- s.close();
- c.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment