View Single Post
Old 06-24-2012, 10:34 PM   PM User | #1
brood_snow
New to the CF scene

 
Join Date: Jun 2012
Posts: 5
Thanks: 0
Thanked 1 Time in 1 Post
brood_snow is an unknown quantity at this point
Question Error accessing a static method (JSP, Java)

JSP file
......................................…
Code:
//reading params from the form
String name = request.getParameter("name");
String year_prime = request.getParameter("year");
int year = Integer.parseInt(year_prime);

//inserting the params into table Students
StudentsManager.getInstance().
fillStudents(name, year);
// here I have the "fillStudents underlined"
......................................…
_____________________________________

Java file
________

Code:
public class StudentsManager {

private static StudentsManager instance;

private StudentsManager(){

}

public static StudentsManager getInstance(){
if (instance == null){
instance = new StudentsManager();
}
return instance;
}

public static void fillStudents(String name, int year){
Connection con = ConnectionsManager.getInstance()
.getConnection(); 
Statement stmt = ConnectionsManager.getInstance()
.getStatement(con);

try {
stmt.executeUpdate("insert into students(name,year) values('"+name+"', year)");
} catch (SQLException e) {
e.printStackTrace();
}
}
......................................…

The error says:

- The method fillStudents(String, int) is undefined the type StudentsManager.

The warning says:

- The static method fillStudents(String, int) from the type StudentsManager should be accessed in a static way.

brood_snow is offline   Reply With Quote
Users who have thanked brood_snow for this post:
anne12 (07-02-2012)