I am unable to update a record using sql statement in java. The
variable numUpdated returns 0, so I think something is wrong with my
code. The objective on thiis numUpdated variable was to return the
number of rows changed. Please help!
Code
------------------------------------------------------------------------------------------------------------------------------------
import java.sql.*;
public class simpleConn
{
Connection con;
Statement s;
ResultSet rs;
public simpleConn()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String filename = "Students.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver
(*.mdb)}; DBQ=" +
filename.trim() + ";DriverID=22; READONLY=false}";
con = DriverManager.getConnection(database, "", "");
s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
s.execute("select * from tStudents");
String strUpdate = "Update tStudents set Name = 'Mark', Course =
'IELTS' where No = 15";
int numUpdated = s.executeUpdate(strUpdate);
System.out.println("updated rows" + numUpdated);
}
catch (Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
simpleConn su = new simpleConn();
}
}
--------------------------------------------------------------------------------------------------------------------------------
zhaoyh.hxtt@gmail.com - 24 Nov 2005 16:59 GMT
Try "select count(*) from tStudents where No = 15" to make sure your
where clause is valid.