gpt4 book ai didi

java - java onnect后选择一个postgres数据库

转载 作者:行者123 更新时间:2023-11-29 12:24:22 25 4
gpt4 key购买 nike

<分区>

这段代码连接abd创建了一个数据库,如何选择创建的数据库来使用它?

public class Connect {

public static void main(String[] args) {
Connection connection = null;
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/","postgres", "12345");


Statement statement = connection.createStatement();
statement.execute("CREATE DATABASE mydb");
//now I hav to connect to mydb

connection.close();
} catch (ClassNotFoundException ex) {
Logger.getLogger(OracleToPostgres.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(OracleToPostgres.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

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