aspose file tools*
The moose likes Beginning Java and the fly likes problem to create instance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "problem to create instance" Watch "problem to create instance" New topic
Author

problem to create instance

pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
Hi,

I have one java file that contains sql connection code and the other is bean , where i want to create instance of sql connection class but it gives error i.e....

can not find symbol

symbol : class sqlconn
location: class dbbean.addlevelbean

where is problem???
----------------------------------

package dbbean;

import java.sql.*;
import javax.sql.*;

public class sqlconn
{



public sqlconn()
{

}

public Connection connectdb()
{

Connection conn = null;

try {

Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc racle:thin:@10.100.212.244:1521 b","usr","pwd");

} catch (SQLException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}

return conn;

}

public void closedb(Connection connt,Statement stmnt)
{
if(connt!=null)
{
try {
connt.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}


if(stmnt!=null)
{
try {
stmnt.close();
} catch(Exception e) {
System.out.println(e.getMessage());
}
}

}



}




////////////////// bean where i need an instance of sql conn.............

package dbbean;

import java.sql.*;

public class addlevelbean
{

private String name;
private String desc;

private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;

public addlevelbean()
{
try{


sqlconn sqlobj = new sqlconn();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
}
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
import required class
pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
i checked after importing, but problem remains same
pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
i have two classes let one.class and two.class ,that belong to one package i.e dbbean

so i have specified it at top in both classes i.e package dbbean

now when i want to create one class instance in other class and try to it compile,it gives error i.e.

can not find symbol
symbol : one.class
location : dbbean.one.class

but when i remove statement : package dbbean; from both files
then no problem , it compiled successfully.

but i need to be call class from jsp by using <jsp:useBean> tag. so i have
to specify path "dbbean.one.class"

wat is problem?
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,

I am not clear with your question. it would be better if you could post some of the executable code. I assume one of the classes is not in the package.
For your information : use code tags while posting your code
bye for now
sat
pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
HI,


// THIS IS MY FIRST CLASS...

package dbbean;

public class one
{
one()
{
System.out.println("I m in one class");
}
}


// THIS IS MY SECOND CLASS......

package dbbean;
import dbbean.*;

public class two
{
two()
{
System.out.println("I m in second class");
}

one obj4one = new one(); // Problem is here , when creating instance

}


//-------------------

it gives error i.e - can not find symbol
symbol : class one
location : class dbbean.two


any body to sort out this problem. what i missing here?

Thanks in advance
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,

Do the following in your command line. I assume your jdk bin is residing at the following drive. i.e F:\j2sdk1.4.2\bin
Type the following in your command line

F:\j2sdk1.4.2\bin\javac -sourcepath F:\j2sdk1.4.2\bin\dbbean dbbean\one.java

F:\j2sdk1.4.2\bin\javac -sourcepath F:\j2sdk1.4.2\bin\dbbean dbbean\second.java


Let me know if it works

bye for now
sat
pavan sharma
Greenhorn

Joined: Dec 19, 2006
Posts: 21
Hi all,

i got my answer.

actually i am compiling one of class with in dbbean package.....so it create problem.


if you try to compile both classes that belong same package from outside, then there is no problem and both compiled successfully.

javac dbbean/*.java no problem

but if you are in dbbean and

javac one.java problem


any way thanks for replying to this question
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: problem to create instance