File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bean New class wont compile

 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harsha Huddar
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guess ur reqmt needs u to make an array of Deitel objects = size of resultset.Whats the stacktrace anyways?
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac - verbose deiteldatabean.java

your class is called:
public class DeitelDataBean
Java is case sensitive.
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
don't you need to import the Deitel class in order to use it?
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its in the same package bank.......
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(using the
why the last line is outside the class? did I miss any bracket?
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry newbie!
 
Mike Alford
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since there is no JSP dimension to this question, I'm moving it along to the Java in General(intermediate) forum.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic