Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
- String labels[] = new String[10];
- int i=0;
- try{
- Class.forName("java.sql.Driver");
- Connection con=DriverManager.getConnection("jdbc:mysql://localhost/bookstore","root","root");
- Statement stmt = con.createStatement();
- String query="select category from inventorymain;";
- ResultSet rs=stmt.executeQuery(query);
- while(rs.next()){
- labels[i]=rs.getString("category");
- i++;
- //dlm.addElement(rs.getString("category"));
- }
- rs.close();
- stmt.close();
- con.close();
- }
- catch(Exception e1){
- e1.printStackTrace();
- }finally{
- }
- jList1.setListData(labels );
- this get executed after i click on the jlist box
- this is my jbutton code
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- String category=(String)jList1.getSelectedValue();
- System.out.print(""+category);
- }
- this problem here is that always gives my selected value as null and selected index as -1 for all values
- almost tried all solution on stackflow but not found any working for mine
Add Comment
Please, Sign In to add comment