Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ajax autocomplete

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am using a ajax autocomplete component from http://www.dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-list.

My problem is that i get a SQL error if the ajax component calls the servlet faster than it can handle. The error is:
com.mysql.jdbc.exceptions.MySQLNonTransientConnectionException: No operations allowed after statement closed.

Let�s say the number of letters to be entered is 3 before a servlet lookup is performed. If the user enters 3 letters ('pet') it works fine. But if the user enters 4 letters (too fast) the ajax component calls the servlet twice ('pet') and ('pete'), and an error occurs.

I can avoid the the above error by doing the servlet synchronized, but is that a good solution? Any other ways to solve the problem?

public synchronized void service ( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
}

Thanks in advance.

[ January 02, 2009: Message edited by: Jeppe Sommer ]
[ January 02, 2009: Message edited by: Jeppe Sommer ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it sounds as if your server components are poorly written. There should be no issues with conflicts between the separate queries. I'd check your server code to make sure you are following correct practices.
[ January 02, 2009: Message edited by: Bear Bibeault ]
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my servlet code:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic