gpt4 book ai didi

Java:如何打印数据库中的行?

转载 作者:搜寻专家 更新时间:2023-10-30 21:40:32 25 4
gpt4 key购买 nike

<分区>

我有这个程序:

class DataRetrieve {

DataRetrieve() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/phonebook", "root", "1234");
Statement st = con.createStatement();
st.executeQuery("select * from contacts");
}
catch(Exception e) {
e.printStackTrace();
}
}
}

public class MainProgram {

public static void main(String[] args) {
DataRetrieve dr = new DataRetrieve();
//here i want to print that table rows into Console using this
System.out.println(); // How do you print here that table rows?
}
}

谁能解释一下如何在 System.out.println 中打印这个数据库信息?

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