Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / November 2005

Tip: Looking for answers? Try searching our database.

Unable to update record in java

Thread view: 
Ifloat@gmail.com - 24 Nov 2005 14:45 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.