aspose file tools*
The moose likes JDBC and the fly likes fail to update. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "fail to update." Watch "fail to update." New topic
Author

fail to update.

joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9


the result was
java.sql.SQLException: No data found
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Error in row
java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Invalid cursor position; no keyset defined


anyone can help ?

[Added code tags - see UseCodeTags for details]
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 860

It looks like you haven't established the cursor position.

You can only update something that you have already retrieved or use a Where clause in standard sql/jdbc.

WP
joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
can you teach me what i need to do ?? i am new in this == was helping my friend to solve this problem.
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Welcome to JavaRanch!

You can see an example here. If you're still having trouble post a small example that shows how you create the query and just update one field.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

You haven't shown us what sort of result set you have, as this only works on certain types (after a quick read of the API)

http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html
joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
Greg Charles wrote:Welcome to JavaRanch!

You can see an example here. If you're still having trouble post a small example that shows how you create the query and just update one field.


thanks! Greg.
I type the exactly what the page have, but still give me the same error. the example :


updateButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){

int id = 520;
String city = "KL";


try{

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery("select * from Employee");
resultSet.first();

resultSet.updateInt("EmpID", id);
resultSet.updateString("City", city);

resultSet.updateRow();
JOptionPane.showMessageDialog(null,"Record updated.");


}catch(Exception ex){
System.out.println(ex.toString());
}
}
});


joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
Wendy Gibbons wrote:You haven't shown us what sort of result set you have, as this only works on certain types (after a quick read of the API)

http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html


do you mean this i missed?

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery("select * from Employee");
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

joo how wrote:
Wendy Gibbons wrote:You haven't shown us what sort of result set you have, as this only works on certain types (after a quick read of the API)

http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html


do you mean this i missed?

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery("select * from Employee");


yes in the first post, but not the later post.
joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
Wendy Gibbons wrote:
joo how wrote:
Wendy Gibbons wrote:You haven't shown us what sort of result set you have, as this only works on certain types (after a quick read of the API)

http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html


do you mean this i missed?

statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
resultSet = statement.executeQuery("select * from Employee");


yes in the first post, but not the later post.



I added resultSet.absolute(1);
but still giving me the error : java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Error in row.
joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
Guys! thanks! i solved it
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Good for you! It would be nice if you could explain how you fixed it. Then everyone learns!
joo how
Greenhorn

Joined: Apr 18, 2012
Posts: 9
haha. sure!

one of my friend told me the reason why error in row is because
1. One or more required fields were not filled
2. One of entered values do not conform field type (character values in numeric or date fields)
3. You trying to enter a value into field which is of Autonumber type.
4. You have a relationship between tables that requires you to put into foreign key field one of existing values from another table. If you put value that don't exist in another table you see the same error.

then i found there is one data type in access was wrong. so, after i changed it. it works!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2771
    
  10

Great, thanks! I hope you'll stick around and ask and/or answer some more questions here!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: fail to update.
 
Similar Threads
SQL error
servlets and sql
SQL Exception
ClassNotFoundException
Data being retrieved even though MySQL driver is not loaded