删除数据
删除某个uid为1001的所有数据
public class DelJDBC {
public static void main(String args[]) {
Connection conn = null;
Statement stmt = null;
try{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://139.224.168.86:5432/doc","citybrain", "Tsdb2gaia");
conn.setAutoCommit(false);
stmt = conn.createStatement();
String sql = "DELETE FROM tsdb_test WHERE uid=1001;";
stmt.executeUpdate(sql);
conn.commit();
// 数据库默认是1s刷新
Thread.sleep(2000);
ResultSet rs = stmt.executeQuery( "SELECT uid, time, ST_AsText(position) AS pos FROM tsdb_test;" );
while ( rs.next() ) {
long id = rs.getLong("uid");
String time = rs.getString("time");
String position = rs.getString("pos");
System.out.println( "uid = " + id + ", time = " + time + ", position = " + position );
System.out.println();
}
rs.close();
stmt.close();
conn.commit();
conn.close();
} catch (Exception e) {
System.err.println(e.getClass().getName() + " : " + e.getMessage());
System.exit(0);
}
System.out.println("delete successfully");
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。
评论