Guest User

Untitled

a guest
Feb 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
  2.  
  3. String labels[] = new String[10];
  4. int i=0;
  5. try{
  6. Class.forName("java.sql.Driver");
  7. Connection con=DriverManager.getConnection("jdbc:mysql://localhost/bookstore","root","root");
  8. Statement stmt = con.createStatement();
  9. String query="select category from inventorymain;";
  10. ResultSet rs=stmt.executeQuery(query);
  11. while(rs.next()){
  12. labels[i]=rs.getString("category");
  13. i++;
  14. //dlm.addElement(rs.getString("category"));
  15. }
  16. rs.close();
  17. stmt.close();
  18. con.close();
  19. }
  20. catch(Exception e1){
  21. e1.printStackTrace();
  22. }finally{
  23. }
  24. jList1.setListData(labels );
  25. this get executed after i click on the jlist box
  26. this is my jbutton code
  27. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  28. String category=(String)jList1.getSelectedValue();
  29. System.out.print(""+category);
  30. }
  31.  
  32. this problem here is that always gives my selected value as null and selected index as -1 for all values
  33. almost tried all solution on stackflow but not found any working for mine
Add Comment
Please, Sign In to add comment