• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error accessing a static method (JSP, Java)

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Kyupa Supa
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



 
reply
    Bookmark Topic Watch Topic
  • New Topic