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.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, String data_m, String data_t,String data_c, String sector )
- {
- System.out.println("Stwarzam nowa tabele w bazie danych o nazwie czujnik");
- Properties props = new Properties();
- props.setProperty("user","psmorczewski");
- props.setProperty("password","3uSMk2Yu2v4pbgwL");
- props.setProperty("ssl","false");
- String polaczenieURL = "jdbc:mysql://157.158.81.79:33306/psmorczewski";
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- Connection connect=DriverManager.getConnection(polaczenieURL,props);
- Statement stmt=connect.createStatement();
- System.out.println("Prawidlowo polaczylem sie za baza danych");
- /*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+"', '"+data_m+"', '"+data_t+"','"+data_c+"','"+sector+"')");
- connect.close();
- }
- catch(ClassNotFoundException wyjatek)
- {
- System.out.println("Problem ze sterownikiem");
- }
- catch(SQLException wyjatek)
- {
- //e.printStackTrace();
- System.out.println("Problem z logowaniem\nProsze sprawdzic:\n nazwę użytkownika, hasło, nazwę bazy danych lub adres IP serwera");
- System.out.println("SQLException: " + wyjatek.getMessage());
- System.out.println("SQLState: " + wyjatek.getSQLState());
- System.out.println("VendorError: " + wyjatek.getErrorCode());
- }
- }
- 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