This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
i have made one package com.beans and put my two src files DBConnection.java and userInfoBean.java in that package.in the constructor of userInfobean class i m trying to create object of DBConnection class to establish database conncetion. following error comes ---------- Java Compiler ---------- userInfoBean.java:185: cannot find symbol symbol : variable DBConnection location: class com.beans.userInfoBean Connection tempCon = DBConnection.con; ^ userInfoBean.java:210: password is already defined in chkUser(java.lang.String,java.lang.String) String password = getPassword(); ^ userInfoBean.java:230: cannot find symbol symbol : class DBConnection location: class com.beans.userInfoBean DBConnection db = new DBConnection(); ^ userInfoBean.java:230: cannot find symbol symbol : class DBConnection location: class com.beans.userInfoBean DBConnection db = new DBConnection(); ^ 4 errors userInfobean.java package com.beans; //import com.beans.*; import java.io.*; import java.sql.*; import oracle.jdbc.driver.*; /* Classes available in Classes12.jar file */ import oracle.jdbc.*; /* Classes available in Classes12.jar file */
/*classPath = System.getProperty("java.class.path","."); System.out.println("System Path is "+classPath);*/
// Load (and therefore register) the Oracle Driver Class.forName("oracle.jdbc.driver.OracleDriver");
// Get a Connection to the database //cssid con = DriverManager.getConnection( "jdbc racle:thin:@turing.cs.lamar.edu:1521:sidcs", "group07", "sholay"); // Replace group_name and password with your group username and password // Create a Statement object stmt = con.createStatement();
// Execute an SQL query, get a ResultSet rs = stmt.executeQuery("SELECT SID FROM STUDENT");
i am compiling from c:\project\com\beans directory...i don't know why its not allowing me to use the class that is in the same package and declared as public
SCJP 1.4<br />SCWCD 1.4(91%)<br />Working on SCJD -Bodgitt & Scrapper Constructions...<br /> <br />"It takes 43 muscles to frown & 17 to smile but it doen't take any to just sit there with a dumb look on your face .. Keep Smiling "
Because you have packages, you need to correctly set you classpath. Since you are compiling from the com/beans directory, when it tries to import your DBConnection class, it is trying to look in the com/beans/com/beans directory. It will try to take the directory you are compiling in and add the package directories, which obviously doesn't exist.
You need to set your classpath to c:\project, and compile from that directory like
You should also change this classes name to UserInfoBean, capitaliz the U in User.
In addtion to Mark's Post Please check the signature of method chkUser, public boolean chkUser(String sid,String password) It has String password in aguement and same time you are declaring a varibale with same name inside the method.