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 Bean New class wont compile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Bean New class wont compile" Watch "Bean New class wont compile" New topic
Author

Bean New class wont compile

Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
Doing database connection fine using bean to get data for a jsp page.
Got a resultset while loop as follows.. but JAVAC won't compile.. objects to NEW instance of class...Don't understand why?
public ArrayList getGuestList() throws SQLException
{
ArrayList guestList = new ArrayList();
Statement selectStamt = con.createStatement();
String query = "SELECT LName, LPassword FROM Lecturer";

ResultSet sresult= selectStamt.executeQuery(query);
while ( sresult.next() ) {
Deitel guest = new Deitel();
guest.setName( sresult.getString(1));
guest.setPwd( sresult.getString(2));
guestList.add(guest);
}
return guestList;
}
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
welcome to the ranch, mike.
Doing database connection fine using bean to get data for a jsp page.
Got a resultset while loop as follows..

so you say it works without compiling? I don't understand, I need more info. If it doesn't compile, can you share with us what the error is? that would help a little bit


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Harsha Huddar
Greenhorn

Joined: Oct 03, 2003
Posts: 23
Guess ur reqmt needs u to make an array of Deitel objects = size of resultset.Whats the stacktrace anyways?
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
The connection code to the database works fine as I have tested that before so I know that that part is working. I changed the way the recordset returns the data in the code fragment which I put in the message.
It seems to be the new instance that doesn;t now compile
javac - verbose deiteldatabean.java
deiteldatabean.java:9:calss DeitelDataBean is public, should be declared in a file named DeitelDataBean.java
public class DeitelDataBean
^
Deiteldatabean.java:68: cannot resolve symbol
symbol: class Deitel
location:class bank.deitelDataBean
Source
package bank;

import java.sql.*;
import java.io.*;
import java.util.*;
import bank.*;
public class DeitelDataBean
{
private PreparedStatement addRecord, getRecords;
private static Connection con = null;

public DeitelDataBean()

{
}

public String ConnectToDB()
{
//connection string variables
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String sURL = "jdbc dbc:HNDDB";
String sUsername = "ALFORD";
String sPassword = "";
try
{
//connect to driver

Class.forName(DBDriver).newInstance();
}
catch( Exception e )
{
return "Failed - test";
//"Failed to Connect to Driver";

}
try
{
// setup connection
con = DriverManager.getConnection ( sURL, sUsername, sPassword);
}
catch (Exception e)
{
return "Failed 2";
// "Failed to Connect";
}


return "Connected okay";
}
public ArrayList getGuestList() throws SQLException
{
ArrayList guestList = new ArrayList();
Statement selectStamt = con.createStatement();
String query = "SELECT LName, LPassword FROM Lecturer";

ResultSet sresult= selectStamt.executeQuery(query);
while ( sresult.next() ) {
Deitel guest = new Deitel();
guest.setName( sresult.getString(1));
guest.setPwd( sresult.getString(2));
guestList.add(guest);
}
return guestList;
}
protected void finalize()
{
try {
getRecords.close();
con.close();
}

catch ( SQLException sqlException ) {
sqlException.printStackTrace();
}

}
}
Deitel guest = new Deitel();
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
javac - verbose deiteldatabean.java

your class is called:
public class DeitelDataBean
Java is case sensitive.
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
yeah that could be done.....ermm...... code is ArrayList deitelList = new ArrayList[1..recordset] i think...tho not sure....dont no wot stacktrace is...
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
Andres... Thanks... That clears the 1st error but the other error is still the same... Any other ideas... I was wondering if there is a jar file I'm missing or something?
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
don't you need to import the Deitel class in order to use it?
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
Andres.. thanks for that but it will only be happy with import bank.*; however still doesn't solve problem and I get the same errors...
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Mike Alford:
Andres.. thanks for that but it will only be happy with import bank.*; however still doesn't solve problem and I get the same errors...

well, in which package is your Deitel class?
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
Its in the same package bank.......
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
The class that i want to create new instance of is just has getter setter methods in it such as getName() etc.... if thats any help
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
(using the
why the last line is outside the class? did I miss any bracket?
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
no u didnt miss out a bracket....the last line is a comment....however i tried putting in the [code] tag and had more errors
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Mike Alford:
no u didnt miss out a bracket....the last line is a comment....however i tried putting in the [code] tag and had more errors

no, the [code] tag is used here in JR to make the code clearer when you post
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
sorry newbie!
Mike Alford
Greenhorn

Joined: Mar 02, 2004
Posts: 10
just had a thought .... am doing this in notepad and the classpath might be wrong hence the errors....am gonna download JDeveloper and see if it compiles through that....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Since there is no JSP dimension to this question, I'm moving it along to the Java in General(intermediate) forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean New class wont compile