📅  最后修改于: 2023-12-03 15:35:22.258000             🧑  作者: Mango
Transbase 和 Yanza 都是关系型数据库管理系统,用于数据存储与查询。但它们有以下不同点:
import java.sql.*;
public class TransbaseExample {
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try {
// 连接数据库
Class.forName("com.toshiba.t3.jdbc.T3Driver");
conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mydb","username","password");
// 执行查询
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM users");
// 处理结果集
while (rs.next()) {
int id = rs.getInt("id");
String name = rs.getString("name");
int age = rs.getInt("age");
System.out.println(id + " " + name + " " + age);
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭连接和资源
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
import yanza
# 连接数据库
conn = yanza.connect('localhost', 5432, 'mydb', 'username', 'password')
# 查询数据
rows = conn.execute("SELECT * FROM users")
# 处理结果集
for row in rows:
id = row[0]
name = row[1]
age = row[2]
print(id, name, age)
# 关闭连接
conn.close()
综上所述,Transbase 和 Yanza 都是可靠的数据库管理系统,选择适合自己场景的数据库才是最重要的。