Forums Register Login

problem to create instance

+Pie Number of slices to send: Send
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());
}
}
}
+Pie Number of slices to send: Send
import required class
+Pie Number of slices to send: Send
i checked after importing, but problem remains same
+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
What a show! What atmosphere! What fun! What a tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1192 times.
Similar Threads
connection call
Problem in usebean
Simple JDBC problem - Connection throws Nullpointerexception
connection
IBM Websphere 5 Connection Pool
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:20:20.