I need to know how to access two tables which has some reference values within the table.I need the Java Code to Fetch Both the tables values which are same and have to display it

Of course not. The first reply is a link to a place where you can hire someone to do it for you, if that is what you want. No one here is going to do it for you.

The second reply contains a link to a good Orcale forum where you can ask about the SQL to be used, and a link to the JDBC Tutorial, so you can learn how to create and use DB connections.

I need to know how to access two tables which has some reference values within the table.I need the Java Code to Fetch Both the tables values which are same and have to display it

Dear,

There is no code of Java to fetch data from databases. Obviously, it is the SQL statements. You want to fetch data from two tables based upon the reference value; So, think about Database object Views or write down Joins (select query).

String sql;

   sql="select a.col1,a.col2,b.col1,b.col2 from table1 a, table2 b where a.col1=b.col1";
  
  // Load a driver
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  // Establish DB Connection
  Connection cn=DriverManager.getConnection("jdbc:odbc:yourdsn","db_username","db_password");
 Statement st=cn.createStatement();

  ResultSet rs=st.executeQuery(sql);

  while(rs.next()) {
        System.out.println(rs.getString(1) + " " + rs.getString(2) + ....);
  }
  rs.close();
  st.close();
  cn.close();
This article has been dead for over six months. Start a new discussion instead.