Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
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)
Old 06-25-2012, 02:27 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Its not being accessed statically. getInstance returns an instance of StudentsManager. Either call fillStudents directly off of the StudentsManager, or change fillStudents to a non static method.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
anne12 (07-02-2012)
Old 06-27-2012, 01:41 PM   PM User | #3
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
Smile Yup, it worked

It worked!

thanks a lot
brood_snow is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:07 PM.


Advertisement
Log in to turn off these ads.