File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes program to make  start-connect by (oracle ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "program to make  start-connect by (oracle )" Watch "program to make  start-connect by (oracle )" New topic
Author

program to make start-connect by (oracle )

amit taneja
Ranch Hand

Joined: Mar 14, 2003
Posts: 810
Hi
I am only simply making the program to have output like given in this page
I have coded in core-java with database in MS-Access having "testing" as System DSN.

In database table "relation" having only two column viz "parent" and "child"

PLEASE HELP ME TO GET FIRST OUTPUT GIVEN IN THE ABOVE LINK.

I tried it but getting error
D:\java_prac>javac db/DBConnection.java
db/DBConnection.java:43: rs1 is already defined in child(int)
ResultSet rs1= stmt1.executeQuery("SELECT * from relation where
parent=0");
^
db/DBConnection.java:45: rs1 is already defined in child(int)
ResultSet rs1= stmt1.executeQuery("SELECT * from relation where
parent="+parent);
^
2 errors

D:\java_prac>




following is the java code tried

-------------------

package db;

import java.util.*;
import java.sql.*;

public class DBConnection {

public Connection getConnection()
{
Connection con =null;

String dbDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String url= "jdbc dbc:testing";
try
{
Class.forName(dbDriver);
con = DriverManager.getConnection(url);
}
catch(Exception e)
{
System.out.println("Exception caught "+e);
e.printStackTrace();
}
return con;

}

public static void main(String args[]){

DBConnection dbcon= new DBConnection();
dbcon.child(0);
}


void child(int parent) {
int a=0;
//DBConnection dbcon1= new DBConnection();
Connection con1= this.getConnection();
Statement stmt1=con1.createStatement();
ResultSet rs1=null;

if(parent==0) {
ResultSet rs1= stmt1.executeQuery("SELECT * from relation where parent=0");
}else {
ResultSet rs1= stmt1.executeQuery("SELECT * from relation where parent="+parent);
}
if(rs1.next())
{
a=rs1.getInt(2);
System.out.println('\n' +" ");
while(rs1.next()) {
a=rs1.getInt(2);
System.out.println('\n' +" ");
DBConnection dbcon1= new DBConnection();
dbcon1.child(a);
}
}
else
return;
}
}

-----------

with reference to above link I put the entries shown as insert in above link page... but instead of null i putted "0"


HELP ME TO FIGURE IT OUT


REGARDS,
AMIT


Thanks and Regards, Amit Taneja
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

You only need to declare a variable once in a given method or class; after that you can refer to it without redeclaring it. To "declare" a variable, you give both its name and its type. This is a declaration:

ResultSet rs1 = null;

To refer to that variable again, you just use the name, and not the type:

rs1 = stmt1.executeQuery("SELECT * from relation where parent=0");


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: program to make start-connect by (oracle )
 
Similar Threads
set ajax response in parent window field without refreshing the parent window
multiple processes... only want one
Who can help me resolve this big problem?
RMI Exception! Please give me a hand!
Who can help me resolve this big problem?