Results 1 to 2 of 2

Thread: Help

  1. #1
    Shivraj is offline Member
    Join Date
    Mar 2009
    Posts
    13
    Rep Power
    0

    Exclamation Help

    hi

    i have binding database with combo box and i want to when i will click on any item in the combo box then related records are shown. for this purpose i had use connectivity and use ItemStateChanged() event for combobox event but some errors are occured

    please help

    This is my code

    private void cidItemStateChanged(java.awt.event.ItemEvent evt) {
    // TODO add your handling code here:
    ResultSet rs;

    try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbc:odbc:project ","scott","tiger");
    String s="select cltid,cltname from cltdetail where cltid=?";
    PreparedStatement stmt=con.prepareStatement(s);
    int cid1;
    cid1=Integer.parseInt(cid.getSelectedItem());
    stmt.setInt(1,cid1);
    rs=stmt.executeQuery();

    if(rs.next())
    {

    name.setText(rs.getString(2));


    }
    con.close();
    stmt.close();
    }
    catch(Exception e1)
    {
    e1.printStackTrace();
    }
    }

    when i will click on combobox item

    java.lang.NumberFormatException: For input string: " 104"
    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:447)
    at java.lang.Integer.parseInt(Integer.java:497)
    at Sitedetails.cidItemStateChanged(Sitedetails.java:3 65)
    at Sitedetails.access$600(Sitedetails.java:17)
    at Sitedetails$7.itemStateChanged(Sitedetails.java:17 4)
    at java.awt.Choice.processItemEvent(Choice.java:609)
    at java.awt.Choice.processEvent(Choice.java:576)
    at java.awt.Component.dispatchEventImpl(Component.jav a:3984)
    at java.awt.Component.dispatchEvent(Component.java:38 19)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java: 463)
    at java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:110)


    These errors are occured
    whats wrong in coding

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    " 104", there exist a space,
    remove it is ok

    i wonder why your code can compile, as Integer.parseInt(Object) should not exist
    Last edited by mtyoung; 03-20-2009 at 11:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •