Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.Properties;
- import com.pi4j.io.gpio.PinState;
- import java.sql.*;
- public class Baza_danych
- {
- static String daneZBazy;
- public static void Baza_danych2(int id_sensor, String data_measure, String data_time,String data_calibration, String sector )
- {
- Properties props = new Properties();
- props.setProperty("user","psmorczewski");
- props.setProperty("password","3uSMk2Yu2v4pbgwL");
- props.setProperty("useSSL","false");
- String polaczenieURL = "jdbc:mysql://157.158.81.79:33306/psmorczewski";
- try
- { DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
- Date time_ = new Date();
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect=DriverManager.getConnection(polaczenieURL,props);
- Statement stmt=connect.createStatement();
- System.out.println("Prawidlowo połączylem sie z Bazą danych psmorczewski");
- /*String sql = "CREATE TABLE SENSOR_MEASUREMENT " +
- " (id_sensor VARCHAR(255), " +
- " data_time VARCHAR(255), "+
- " sector_sensor VARCHAR(255), " +
- " data_measure VARCHAR(255), " +
- " data_calibration VARCHAR(255)) " ;
- stmt.executeUpdate(sql);
- System.out.println("Created table in given database...");
- */
- stmt.executeUpdate("INSERT INTO SENSOR_MEASUREMENT(id_sensor,data_measure,data_time,data_calibration,sector_sensor) VALUES ('"+id_sensor+"', '"+data_measure+"', '"+data_time+"','"+data_calibration+"','"+sector+"')");
- connect.close();
- }
- catch(ClassNotFoundException wyjatek)
- {
- System.out.println("Database driver problem");
- }
- catch(SQLException wyjatek)
- {
- //e.printStackTrace();
- DateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
- Date time_begin = new Date();
- System.out.println("Problem with login\n PLEASE CHECK:\n user name, password, database name, IP adress");
- //System.out.println("SQLException: " + wyjatek.getMessage());
- //System.out.println("SQLState: " + wyjatek.getSQLState());
- System.out.println("VendorError: " + wyjatek.getErrorCode());
- }
- }
- public static int Connecting() throws ClassNotFoundException
- { Connection con;
- int verification=1;
- Properties props = new Properties();
- props.setProperty("user","psmorczewski");
- props.setProperty("password","3uSMk2Yu2v4pbgwL");
- props.setProperty("useSSL","false");
- try {
- String polaczenieURL = "jdbc:mysql://157.158.81.79:33306/psmorczewski";
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(polaczenieURL,props);
- System.out.println("Connected to database psmorczewski");
- verification=1;
- }
- catch (SQLException e)
- {
- System.out.println("No connection to base");
- verification=0;
- //e.printStackTrace();
- }
- return verification;
- }
- static void wyswietlDaneZBazy(ResultSet rs)
- {
- try
- {
- daneZBazy = rs.getString(1);
- System.out.println("\n" + daneZBazy + " ");
- daneZBazy = rs.getString(2);
- System.out.println(daneZBazy + " ");
- daneZBazy = rs.getString(3);
- System.out.println(daneZBazy);
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
Add Comment
Please, Sign In to add comment