Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jdbc inserting row problem

Status
Not open for further replies.

ajoce

Programmer
Aug 4, 2003
14
PH
can anyone help me. i have this prob in inserting a new row in my database. i am using microsoft sql as my database, using northwind database (the sample database in mssql).

my code is :

con = DriverManager.getConnection("jdbc:eek:dbc:nwind");
stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet uprs = stmt.executeQuery("SELECT * FROM employees");
uprs.moveToInsertRow();
uprs.updateInt("EmployeeID",20);
uprs.updateString("LastName","TestName");
uprs.updateString("FirstName","TestFirst");
uprs.insertRow();
uprs.beforeFirst();
while (uprs.next()) {
System.out.println(uprs.getString(1)+" "+uprs.getString(2)+" "+uprs.getString(3));

it always throws an ArrayIndexOutOfBounds exception when it executes the uprs.insertRow(); i cant seem to find what i am missing in my code. can anyone help?

thank you in advance
 
AFAIK the JDBC-ODBC bridge driver does not support the action you're attempting. Your insertrow() command would move the ResultSet to beyond its end, thus causing the Exception.

Use a separate insert statement instead.
 
how can i use another insert statement? like creating a different result set and calling the insert statement from there? pls help

thanks for the reply jwenting =)
 
Try using directly ...
stmt.executeUpdate(your sql sentence);


Salih Sipahi
Software Engineer.
City of Istanbul Turkey
s.sipahi@sahinlerholding.com.tr
 
i wanna use the result sets methods without using any sql statements. is there another way? but ill try what you suggested =) thank you Hattusas
 
Only way would be to use another JDBC driver which does support the features you want.

I'm pretty certain there are some out there, but I don't know examples for MS Access or MS SQL Server.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top