Hi

iam having really an annoying problem .. iam inserting some to DB ( Mysql ) throught ( jdbc ) from ( servlets ) and want to get the last insert id to move on .. but just it doesnt work .. always throws NULL in the exception ..

this is main code for initiating the DB :

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      		connection = DriverManager.getConnection( connectionURL, username, password);
            statement = connection.createStatement();

then i insert some :

database.statement.executeUpdate("insert some into watever");

then :

database.statement.executeQuery("select LAST_INSERT_ID()");
// then i try to print database.rs.getInt(1);

I don't know .. it seems like something is wrong

I tried to remove the part ( database.statement or database.rs ) as iam using my own handler .. and tried to use basic and traditional way " Statemenet st ... and ResultSet rs = ... " for both the insertion query and last_insert_id query .. but still the same ..

please any help .. i wanna move on in my program and iam stuck here days ago

thanks

solved it finally .. yesssssss :D:D:D

database.statement.executeUpdate("insert into bag_tables set tablename = '" + tablename + "', ownerid = '" + userid + "', roomid = '" + roomid + "', rated = '" + rated + "', sound = '" + sound + "', tabletype = '" + type + "', timer = '" + timer + "'");
            database.rs = database.statement.getGeneratedKeys();
            int tableid = -1;
            if (database.rs.next()){
                tableid = database.rs.getInt(1);
            }

the best i like in posting topics in forums .. that the first thing it does is to organize ur thoughts :D hehe

This article has been dead for over six months. Start a new discussion instead.