小编Nar*_*yan的帖子

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

我有这个程序:

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?
    }
} 
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释如何打印这个数据库信息System.out.println

java mysql database

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

database ×1

java ×1

mysql ×1