从另一个Java类获取值

时间:2017-04-21 19:04:38

标签: java postgresql jdbc

我想从RandevufiltreSorgu.java获得doktor [0],doktor [1],secilenBolum。我在randevusec中创建了RandevufiltreSorgu类的对象。但是当我运行查询时,我无法获得我想要的值。没有继承使用。我该怎么办?

public class randevusec {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;

    public ResultSet saatler() throws SQLException, Exception {
        randevufiltreSorgu nesne = new randevufiltreSorgu();
        try {
            Class.forName("org.postgresql.Driver");
            conn = DriverManager.getConnection("jdbc:postgresql://localhost:5432/tipmerkezivt", "postgres", "2569");
            ps = conn.prepareStatement(
                    "WITH Q1 AS(\n" + "    select * from doktor natural join bolum where dr_adi='" + nesne.doktor[0]
                            + "' and dr_soyadi='" + nesne.doktor[1] + "' and bolum.b_adi='" + nesne.secilenBolum + "'\n"
                            + "    )\n" + "    select cs_saat from doktorun_programi natural join Q1\n" + "    ",
                    ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
            rs = ps.executeQuery();
            return rs;
        } catch (Exception e) {
            throw new Exception("Bağlantı başarısız!");
        }

        finally {
            conn.close();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

很难理解您的代码,因为它主要使用外语,但您可以做的是构建doktor[0]doktor[1]时,将关键字public static放在它们之前