<dependency> <groupId>org.herd</groupId> <artifactId>herddb-jdbc</artifactId> <version>0.10.0</version> </dependency> import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; String url = "jdbc:herddb:server:localhost:7000"; String username = "your_username"; String password = "your_password"; try (Connection connection = DriverManager.getConnection(url, username, password)) { } catch (SQLException e) { e.printStackTrace(); } try (Statement statement = connection.createStatement()) { String sqlQuery = "SELECT * FROM your_table"; ResultSet resultSet = statement.executeQuery(sqlQuery); while (resultSet.next()) { int id = resultSet.getInt("id"); String name = resultSet.getString("name"); System.out.println("ID: " + id + ", Name: " + name); } String sqlUpdate = "UPDATE your_table SET name='New Name' WHERE id=1"; int updatedRows = statement.executeUpdate(sqlUpdate); System.out.println("Updated rows: " + updatedRows); } catch (SQLException e) { e.printStackTrace(); }


上一篇:
下一篇:
切换中文