added website updates
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
import javafx.scene.input.DataFormat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
|
3
src/META-INF/MANIFEST.MF
Normal file
3
src/META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: main
|
||||
|
87
src/db/Database.java
Executable file
87
src/db/Database.java
Executable file
@ -0,0 +1,87 @@
|
||||
package db;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Vector;
|
||||
|
||||
public abstract class Database {
|
||||
|
||||
protected String user;
|
||||
protected String password;
|
||||
|
||||
protected String host;
|
||||
protected int port;
|
||||
|
||||
protected String dbName;
|
||||
|
||||
public Database(String user, String password, String host, int port, String dbName) {
|
||||
this.user = user;
|
||||
this.password = password;
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public abstract Connection getConnection();
|
||||
|
||||
public static void logToConsole(ResultSet res) {
|
||||
try {
|
||||
|
||||
ResultSetMetaData rsmd = res.getMetaData();
|
||||
|
||||
while (res.next()) {
|
||||
String row = "";
|
||||
|
||||
for (int i = 1; i <= rsmd.getColumnCount(); ++i) {
|
||||
if (row.length() > 0) {
|
||||
row += ", ";
|
||||
}
|
||||
|
||||
if (res.getObject(i) != null) {
|
||||
row +=
|
||||
rsmd.getColumnName(i) +
|
||||
": " +
|
||||
res.getObject(i).toString();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(row);
|
||||
}
|
||||
|
||||
} catch(SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public static DefaultTableModel logToTable(ResultSet res) {
|
||||
try {
|
||||
ResultSetMetaData rsmd = res.getMetaData();
|
||||
Vector<String> columnNames = new Vector<>();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
|
||||
for (int i = 1; i <= columnCount; ++i) {
|
||||
columnNames.add(rsmd.getColumnName(i));
|
||||
}
|
||||
|
||||
Vector<Vector<Object>> data = new Vector<>();
|
||||
|
||||
while(res.next()) {
|
||||
Vector<Object> row = new Vector();
|
||||
|
||||
for (int i = 1; i <= columnCount; ++i) {
|
||||
row.add(res.getObject(i));
|
||||
}
|
||||
|
||||
data.add(row);
|
||||
}
|
||||
|
||||
return new DefaultTableModel(data, columnNames);
|
||||
} catch(SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
37
src/db/MySQLConnector.java
Executable file
37
src/db/MySQLConnector.java
Executable file
@ -0,0 +1,37 @@
|
||||
package db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class MySQLConnector extends Database {
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver").newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public MySQLConnector(String user, String password, String host, int port, String dbName) {
|
||||
super(user, password, host, port, dbName);
|
||||
}
|
||||
|
||||
public Connection getConnection() {
|
||||
Connection con = null;
|
||||
|
||||
try {
|
||||
con = DriverManager.getConnection(
|
||||
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false",
|
||||
user,
|
||||
password);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return con;
|
||||
}
|
||||
|
||||
}
|
37
src/db/PostgreSQLConnector.java
Executable file
37
src/db/PostgreSQLConnector.java
Executable file
@ -0,0 +1,37 @@
|
||||
package db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class PostgreSQLConnector extends Database {
|
||||
|
||||
static {
|
||||
try {
|
||||
Class.forName("org.postgresql.Driver").newInstance();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public PostgreSQLConnector(String user, String password, String host, int port, String dbName) {
|
||||
super(user, password, host, port, dbName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
Connection con = null;
|
||||
|
||||
try {
|
||||
con = DriverManager.getConnection(
|
||||
"jdbc:postgresql://" + host + ":" + port + "/" + dbName,
|
||||
user,
|
||||
password);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return con;
|
||||
}
|
||||
}
|
33
src/db/jdcb.java
Normal file
33
src/db/jdcb.java
Normal file
@ -0,0 +1,33 @@
|
||||
package db;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class jdcb {
|
||||
public void executeQuery(String sql) {
|
||||
Database db = new MySQLConnector(
|
||||
"users",
|
||||
"kOpaIJUjkgb9ur6S",
|
||||
"127.0.0.1",
|
||||
3306,
|
||||
"wasteinformation");
|
||||
|
||||
Connection c = db.getConnection();
|
||||
try {
|
||||
PreparedStatement stmt =
|
||||
c.prepareStatement(sql);
|
||||
|
||||
ResultSet r = stmt.executeQuery();
|
||||
|
||||
DefaultTableModel model = Database.logToTable(r);
|
||||
|
||||
// this.resultTable.setModel(model);
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
import db.jdcb;
|
||||
|
||||
public class main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
/*
|
||||
Date D=new Date();
|
||||
D.getdata();
|
||||
D.printList();
|
||||
/*
|
||||
Thread mythread = new Thread(() -> new Webserver().startserver());
|
||||
mythread.start();
|
||||
*/
|
||||
// Thread mythread = new Thread(() -> new Webserver().startserver());
|
||||
// mythread.start();
|
||||
//
|
||||
//
|
||||
// System.out.println("thread started");
|
||||
|
||||
|
||||
System.out.println("thread started");*/
|
||||
new jdcb().executeQuery("select * from user");
|
||||
}
|
||||
}
|
||||
|
40
src/mqtt.java
Normal file
40
src/mqtt.java
Normal file
@ -0,0 +1,40 @@
|
||||
import org.eclipse.paho.client.mqttv3.MqttClient;
|
||||
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
public class mqtt {
|
||||
public mqtt() {
|
||||
String topic = "MQTT Examples";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://iot.eclipse.org:1883";
|
||||
String clientId = "JavaSample";
|
||||
MemoryPersistence persistence = new MemoryPersistence();
|
||||
|
||||
try {
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: "+broker);
|
||||
sampleClient.connect(connOpts);
|
||||
System.out.println("Connected");
|
||||
System.out.println("Publishing message: "+content);
|
||||
MqttMessage message = new MqttMessage(content.getBytes());
|
||||
message.setQos(qos);
|
||||
sampleClient.publish(topic, message);
|
||||
System.out.println("Message published");
|
||||
sampleClient.disconnect();
|
||||
System.out.println("Disconnected");
|
||||
System.exit(0);
|
||||
} catch(MqttException me) {
|
||||
System.out.println("reason "+me.getReasonCode());
|
||||
System.out.println("msg "+me.getMessage());
|
||||
System.out.println("loc "+me.getLocalizedMessage());
|
||||
System.out.println("cause "+me.getCause());
|
||||
System.out.println("excep "+me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user