java—使用自连接将来自同一数据库列的数据显示为两个不同的jtable列

mbyulnm0  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(256)

我想使用语句中的自连接将来自同一数据库列的数据显示到两个不同的jtable列中。我很确定我的问题在这里,但我不知道如何解决它:

while (rs.next()) {
        String d = rs.getString("a.nrzbor");
        String e = rs.getString("b.nrzbor");
        model.addRow(new Object[]{d, e});
        jTable5.setModel(model);
    }

以下是完整代码:

String de_la = introducereOras1.getText();
    String la = introducereOras2.getText();
    DefaultTableModel model = new DefaultTableModel(new String[]{"nrzbor1", "nrzbor2"}, 0);

    String url = "jdbc:mysql://localhost:3306/aeroport";
    String user = "root";
    String password = "";

    PreparedStatement myStmt = null;
    ResultSet rs = null;

    try{
        Connection myConn = DriverManager.getConnection(url, user, password);
        myStmt = myConn.prepareStatement("SELECT a.nrzbor , b.nrzbor" +
                                    "FROM Zboruri a,Zboruri b\n" +  
                                    "WHERE (a.de_la = ? AND b.de_la = ?) AND (a.la = ? AND b.la = ?);");
        myStmt.setString(1, de_la);
        myStmt.setString(2, la);
        myStmt.setString(3, la);
        myStmt.setString(4, de_la);
        rs = myStmt.executeQuery();
        while (rs.next()) {
            String d = rs.getString("a.nrzbor");
            String e = rs.getString("b.nrzbor");
            model.addRow(new Object[]{d, e});
            jTable5.setModel(model);
        }
    }
    catch(Exception e){
        System.err.println("Got an exception!");
        System.err.println(e.getMessage());
    }

有人能帮我吗?谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题