Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.mysql.fabric.jdbc.FabricMySQLDriver;
- import java.sql.*;
- public class Main {
- static String QUERY_DB_URL = "jdbc:mysql://localhost:3306/new_schema2";
- static String USERNAME = "root";
- static String PASSWORD = "root";
- // Моделька
- public static class UserQuery {
- private Long date;
- private Integer request_id;
- private Integer user_id;
- private String user_name;
- private String platform;
- private String query;
- private Integer query_type;
- public UserQuery() {
- }
- public UserQuery(Long date,
- Integer request_id,
- Integer user_id,
- String user_name,
- String platform,
- String query,
- Integer query_type)
- {
- this.request_id = request_id;
- this.user_id = user_id;
- this.user_name = user_name;
- this.platform = platform;
- this.query = query;
- this.query_type = query_type;
- }
- public Long getDate() {
- return date;
- }
- public void setDate(Long date) {
- this.date = date;
- }
- public Integer getRequest_id() {
- return request_id;
- }
- public void setRequest_id(Integer request_id) {
- this.request_id = request_id;
- }
- public Integer getUser_id() {
- return user_id;
- }
- public void setUser_id(Integer user_id) {
- this.user_id = user_id;
- }
- public String getUser_name() {
- return user_name;
- }
- public void setUser_name(String user_name) {
- this.user_name = user_name;
- }
- public String getPlatform() {
- return platform;
- }
- public void setPlatform(String platform) {
- this.platform = platform;
- }
- public String getQuery() {
- return query;
- }
- public void setQuery(String query) {
- this.query = query;
- }
- public Integer getQuery_type() {
- return query_type;
- }
- public void setQuery_type(Integer query_type) {
- this.query_type = query_type;
- }
- }
- // Пример запросов
- public static UserQuery getUserQuery(int id, Connection connection) {
- try {
- Statement stmt = connection.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT * FROM user WHERE request_id=" + id);
- if(rs.next())
- {
- UserQuery uq = new UserQuery();
- // как-то с найденной записью работать вроде такого
- uq.setQuery(uq.getQuery() + " | отправлено с " + uq.getQuery_type());
- return uq;
- }
- } catch (SQLException ex) {
- ex.printStackTrace();
- }
- return null;
- }
- // Начальная инициализация
- public static void main(String[] args) {
- try {
- Driver driver = new FabricMySQLDriver();
- DriverManager.registerDriver(driver);
- } catch (SQLException e) {
- System.err.print("Не удалось загрузить класс драйвера MySQL\n");
- e.printStackTrace();
- }
- try (Connection connection = DriverManager.getConnection(QUERY_DB_URL, USERNAME, PASSWORD)) {
- getUserQuery(1, connection);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement