PDA

View Full Version : [B]JAVA autocomplete search[/B]


Blade_runner
02-13-2007, 09:49 AM
Hi

I have posted this problem before on this forum still now i am still unable to solve the problem.

Bacically i want that when a user type in text in a textfield,the values in the textfield used to run a query then display the database results on a jlist.

i have a some code,could someone please take a look at my code


private void jTextField77KeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:

String text1 = jTextField77.getText();

System.out.println("KeyPressed******* "+text1);

String sqlCompanySeachD = "SELECT company_id,company_name FROM company WHERE company_name LIKE '%"+text1+"%'";


try
{
this.resultSet = this.connection.executeQuery(sqlCompanySeachD);

while(this.resultSet.next())
{


listModel.addElement(this.resultSet.getString("company_name"));

System.out.println("Company Result.... "+this.resultSet.getString("company_name"));


}

jList10.setModel(listModel);
}

catch(SQLException e)
{
e.printStackTrace(System.err);
}

}

Thank you, any suggestions on how could write this better are welcome
Thanks

Blade_runner
02-13-2007, 10:39 AM
Thanks i managed to get it thanks.