Commit 75d5329b by 周田

fix: 正常获取时间

parent 991beeb7
...@@ -48,22 +48,23 @@ public class Main { ...@@ -48,22 +48,23 @@ public class Main {
// util.insert("t", new HashMap<>(Map.of( // util.insert("t", new HashMap<>(Map.of(
// "ss", "123" // "ss", "123"
// ))); // )));
util.insert( // util.insert(
"s", // "s",
new HashMap<>(Map.of( // new HashMap<>(Map.of(
"ts", new Date(), // "ts", new Date(),
"st", true, // "st", true,
"temperature", 1, // "temperature", 1,
"press", 2 // "press", 2
)) // ))
); // );
//
List<Modbus> list = util.getList("select * from power.s;", Modbus.class); List<Modbus> list = util.getList("select * from power.s;", Modbus.class);
list.forEach(e -> System.out.println(e.toString())); list.forEach(e -> System.out.println(e.toString()));
// System.out.println("==============="); System.out.println("===============");
// Modbus m = util.getOne("select * from power.s;", Modbus.class); Modbus m = util.getOne("select * from power.s;",
// System.out.println(m.toString()); Modbus.class);
System.out.println(m.toString());
} }
} }
\ No newline at end of file
...@@ -18,7 +18,12 @@ public class QueryDemo { ...@@ -18,7 +18,12 @@ public class QueryDemo {
System.out.print(value); System.out.print(value);
System.out.print("\t"); System.out.print("\t");
} }
System.out.println(); System.out.println();
for (int i = 1; i <= meta.getColumnCount(); i++) {
System.out.print(rs.getString(i).getClass().getName());
System.out.print("\t");
}
} }
private static void printColName(ResultSet rs) throws SQLException { private static void printColName(ResultSet rs) throws SQLException {
...@@ -28,20 +33,23 @@ public class QueryDemo { ...@@ -28,20 +33,23 @@ public class QueryDemo {
System.out.print(colLabel); System.out.print(colLabel);
System.out.print("\t"); System.out.print("\t");
} }
System.out.println(); System.out.println();
} }
private static void processResult(ResultSet rs) throws SQLException { private static void processResult(ResultSet rs) throws SQLException {
printColName(rs); printColName(rs);
while (rs.next()) { // while (rs.next()) {
printRow(rs); // printRow(rs);
} // }
rs.next();
printRow(rs);
} }
private static void queryData() throws SQLException { private static void queryData() throws SQLException {
try (Connection conn = getConnection()) { try (Connection conn = getConnection()) {
try (Statement stmt = conn.createStatement()) { try (Statement stmt = conn.createStatement()) {
ResultSet rs = stmt.executeQuery("SELECT AVG(voltage) FROM meters GROUP BY location"); ResultSet rs = stmt.executeQuery("SELECT * FROM power.s");
processResult(rs); processResult(rs);
} }
} }
......
package org.linkor.entities; package org.linkor.entities;
import java.util.Date;
import java.sql.Date;
/** /**
* modbus 数据类 * modbus 数据类
*/ */
public class Modbus { public class Modbus {
Date time; String ts;
boolean st; boolean st;
int temperature; int temperature;
int press; int press;
...@@ -14,19 +15,19 @@ public class Modbus { ...@@ -14,19 +15,19 @@ public class Modbus {
public Modbus() { public Modbus() {
} }
public Modbus(Date time, boolean st, int temperature, int press) { public Modbus(String ts, boolean st, int temperature, int press) {
this.time = time; this.ts = ts;
this.st = st; this.st = st;
this.temperature = temperature; this.temperature = temperature;
this.press = press; this.press = press;
} }
public Date getTime() { public String getTs() {
return time; return ts;
} }
public void setTime(Date time) { public void setTs(String ts) {
this.time = time; this.ts = ts;
} }
public boolean isSt() { public boolean isSt() {
...@@ -56,7 +57,7 @@ public class Modbus { ...@@ -56,7 +57,7 @@ public class Modbus {
@Override @Override
public String toString() { public String toString() {
return "Modbus{" + return "Modbus{" +
"time=" + time + "ts='" + ts + '\'' +
", st=" + st + ", st=" + st +
", temperature=" + temperature + ", temperature=" + temperature +
", press=" + press + ", press=" + press +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment