JDBC

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron

    JDBC

    this code is giving me an excption and I cannot tell why could someone who
    is familiar with jdbc help me out, I am using mysql with jdbc, although the
    exception does not look like it is getting far enough for that to matter.


    Statement stmt = PoolDB.createSt atement(ResultS et.TYPE_SCROLL_ INSENSITIVE,
    ResultSet.CONCU R_UPDATABLE);
    ResultSet Picks = stmt.executeQue ry("SELECT * FROM picks where
    week="+week); // get all the cloums and keys so the rows are updateable
    ResultSet ScoreCalc; //for lookups to another table
    String PlayerOrGoalie; //to determine wich table to look in
    String name;
    String Test;
    while (Picks.next()){ //loop through all the picks
    name=Picks.getS tring(5);
    PlayerOrGoalie= Picks.getString (4)=="G"? "goalie":"playe r"; //select
    the table goalie, or player
    Test="Select WeekOpenScore, CurrentScore from "+PlayerOrGoali e+" where
    name ='"+name+"'";
    System.out.prin tln(Test); //shows the query for debugging
    ScoreCalc =stmt.executeQu ery(Test);
    System.out.prin tln("1"); //verifys that the above line is processed;
    ScoreCalc.first ();
    System.out.prin tln("2"); //verifys that the above line is processed;
    Picks.updateInt ("Score",ScoreC alc.getInt(2)-ScoreCalc.getIn t(1));
    System.out.prin tln("3"); //verifys that the above line is processed;
    Picks.updateRow ();
    System.out.prin tln("4"); //Output never reaches here
    }

    gives me this output

    Select WeekOpenScore, CurrentScore from player where name ='SomeName'
    1
    2
    3
    Exception in thread "main" java.lang.NullP ointerException
    at com.mysql.jdbc. UpdatableResult Set.refreshRow( UpdatableResult Set.java:628)
    at com.mysql.jdbc. UpdatableResult Set.updateRow(U pdatableResultS et.java:1542)
    at Hockey2003.main (Hockey2003.jav a:113)


  • Ron

    #2
    Re: JDBC

    Answered my own question by creating a second statement for the second
    result set so that my first set would not get closed..... silly me


    "Ron" <[email protected] .here> wrote in message
    news:rxmjb.1199 56$ko%.108501@n ews04.bloor.is. net.cable.roger s.com...[color=blue]
    > this code is giving me an excption and I cannot tell why could someone who
    > is familiar with jdbc help me out, I am using mysql with jdbc, although[/color]
    the[color=blue]
    > exception does not look like it is getting far enough for that to matter.
    >
    >
    > Statement stmt =[/color]
    PoolDB.createSt atement(ResultS et.TYPE_SCROLL_ INSENSITIVE,[color=blue]
    > ResultSet.CONCU R_UPDATABLE);
    > ResultSet Picks = stmt.executeQue ry("SELECT * FROM picks where
    > week="+week); // get all the cloums and keys so the rows are[/color]
    updateable[color=blue]
    > ResultSet ScoreCalc; //for lookups to another table
    > String PlayerOrGoalie; //to determine wich table to look in
    > String name;
    > String Test;
    > while (Picks.next()){ //loop through all the picks
    > name=Picks.getS tring(5);
    > PlayerOrGoalie= Picks.getString (4)=="G"? "goalie":"playe r"; //select
    > the table goalie, or player
    > Test="Select WeekOpenScore, CurrentScore from "+PlayerOrGoali e+" where
    > name ='"+name+"'";
    > System.out.prin tln(Test); //shows the query for debugging
    > ScoreCalc =stmt.executeQu ery(Test);
    > System.out.prin tln("1"); //verifys that the above line is processed;
    > ScoreCalc.first ();
    > System.out.prin tln("2"); //verifys that the above line is processed;
    > Picks.updateInt ("Score",ScoreC alc.getInt(2)-ScoreCalc.getIn t(1));
    > System.out.prin tln("3"); //verifys that the above line is processed;
    > Picks.updateRow ();
    > System.out.prin tln("4"); //Output never reaches here
    > }
    >
    > gives me this output
    >
    > Select WeekOpenScore, CurrentScore from player where name ='SomeName'
    > 1
    > 2
    > 3
    > Exception in thread "main" java.lang.NullP ointerException
    > at[/color]
    com.mysql.jdbc. UpdatableResult Set.refreshRow( UpdatableResult Set.java:628)[color=blue]
    > at[/color]
    com.mysql.jdbc. UpdatableResult Set.updateRow(U pdatableResultS et.java:1542)[color=blue]
    > at Hockey2003.main (Hockey2003.jav a:113)
    >
    >[/color]


    Comment

    Working...