File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Error accessing a static method (JSP, Java) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Error accessing a static method (JSP, Java)" Watch "Error accessing a static method (JSP, Java)" New topic
Author

Error accessing a static method (JSP, Java)

Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
JSP file
......................................…

......................................…
______________________________________…

Java file
________


......................................…

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.

I really don't know what to do.
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The getInstance() method seems to indicate you are trying to use a singleton pattern.
Generally with that pattern, the getInstance() method should be static, but none of the other methods on the class.

You obtain the object via the call to getInstance() and then invoke the non static methods on that object.
so



The database code looks a bit dodgy as well.
What is the ConnectionsManager class?
You get both a connection and a statement from it, but then only use the statement.
The general way to use it would be to obtain a connection, and then create the statement from the connection object.
I would also recommend using prepared statements over sql strings like you have to guard against sql injection.

Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
It worked the way you said (with leaving away the "static") for the rest of the methods :)

I use only Statement, but invoking the connection method as well because they are bound together:



The ConnectionsManager.java is:



Concerning PreparedStatement, you're the second one saying that, but well I'm using that insert statement only once.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

Diana Sarbu wrote:you're the second one saying that, but well I'm using that insert statement only once.

So? Is that a good reason to leave your site open to SQL injection?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kyupa Supa
Ranch Hand

Joined: Jun 23, 2012
Posts: 30
Bear Bibeault wrote: So? Is that a good reason to leave your site open to SQL injection?


I read now on Wiki about this. I don't want to sound rude or something but, look, I'm not working on a commercial software now. I'm just making a project and my prof. said to use just Statements, plus I would have to write a few methods more in the java file and I really don't have the time right now. I need to make my project full and working and afterwards, with the remaining time(i hope i'll have it) I'll try to see what I can change in some parts.



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error accessing a static method (JSP, Java)