gpt4 book ai didi

playframework - 游戏框架中的多个数据库

转载 作者:行者123 更新时间:2023-12-04 04:07:15 25 4
gpt4 key购买 nike

我正在尝试与另一个服务器上的另一个数据库建立第二个数据库连接。我们使用的是Play框架1.2.4,我发现了有关1.2.3的以下文档。

http://www.playframework.org/documentation/1.2.3/model#multiple

application.conf:
db_other.url=jdbc:mysql://localhost/test
db_other.driver=com.mysql.jdbc.Driver
db_other.user=root
db_other.pass=

Connection conn = DB.getDBConfig("other").getConnection()

这对我不起作用,因此我进行了更多搜索并找到了以下文章。
本文告诉我,上述配置是从1.3 master分支泄漏出来的,将来将可用...

JPA.getJPAConfig method not found on Play's API

https://play.lighthouseapp.com/projects/57987/tickets/706

谁能给我一种对其他数据库进行简单查询的方法?我想我不是唯一想使用多个数据库的人。

谢谢!

最佳答案

要偶尔从其他数据库读取数据,您也可以使用普通的旧式JDBC:

    Connection c = null;
PreparedStatement pstmt = null;
ResultSet rs = null;

try {
String url = "YourJdbcUrl";
Class.forName("YourDriver").newInstance();
c = DriverManager.getConnection(url, "XXX", "XXX");
pstmt = c.prepareStatement("SELECT * FROM TABLE");
rs = pstmt.executeQuery();
while (rs.next()) {
// Fill your data into Play Model instances here.
}

}catch(Exception e){
e.printStackTrace();
} finally {
try { if (rs != null) rs.close(); } catch (Exception e) {};
try { if (pstmt != null) pstmt.close(); } catch (Exception e) {};
try { if (c != null) c.close(); } catch (Exception e) {};
}

render(...);

关于playframework - 游戏框架中的多个数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9125235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com