从2个表中获取数据而不使用外键Java

时间:2014-04-22 19:04:59

标签: java sql for-loop while-loop derby

您好我试图从2个表中获取数据而不使用foriegn键。我试着用它循环,但没有太多运气。我试图使用order2表中的personid从personnew表中获取具有相同personid的数据..继承我的代码任何建议谢谢..`ResultSetMetaData rsmd = rs.getMetaData();             int numberCols = rsmd.getColumnCount();              ResultSet rs = stmt.executeQuery(" select * from ORDER2");

         int customerid = 0;

         for (int i=1; i<=numberCols; i++)
        {
           if (rs.next()){
            int id = rs.getInt(3);
            System.out.println(id);
            System.out.println("_______");  
            customerid=id;
            List<Integer> x = new ArrayList<Integer>();
            x.add(id);
           }
        }

        while(rs.next())
        {
            int id = rs.getInt(1);
            String restName = rs.getString(2);
            String cityName = rs.getString(3);
            System.out.println(id + "\t\t" + restName + "\t\t" + cityName);
        }

         rs = stmt.executeQuery("select * from PERSONNEW WHERE PERSONID=" +customerid );

        for (int i=1; i<=numberCols; i++)
        {

        }

        while(rs.next())
        {
            int id = rs.getInt(1);
            String restName = rs.getString(2);
            String cityName = rs.getString(3);
            System.out.println("PERSON " + id + "\t\t" + restName + "\t\t" + cityName);
        }
        rs.close();
        stmt.close();
        `

0 个答案:

没有答案