Here's a small sample that updates a row in my Access database. Make sure
that your data source name (Pawnshop) matches. I used the prepareStatement
so I wouldn't have to worry about quoting strings or formatting dates.
java.sql.Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
con = java.sql.DriverManager.getConnection("jdbc:odbc:Pawnshop");
String sql = "UPDATE SystemDefaults SET Address1 = ? WHERE DEFAULT_ID = ?";
java.sql.PreparedStatement stmt = con.prepareStatement(sql);
stmt.setString(1, "123 Some Street");
stmt.setInt(2, 1);
int rows = stmt.executeUpdate();
if( rows != 1 )
System.out.println("Update failed, no records updated");
stmt.close();
} finally {
if( con != null )
con.close();
}
This code updates the record properly. Let me know if this helps at all.
Clayton
----- Original Message -----
From: "Mick Sullivan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: March 11, 2001 10:26 AM
Subject: Re: SIMPLE SQL QUERY.....
> Hi Clayton,
> Thanks for the help, but there is still a new row added into the table
> "parkingPrice". This is what my applyChanges methos looks like now
> public void applyChanges() throws Exception
> {
> Statement statement = connection.createStatement();
>
> String query = "INSERT INTO parkingPrice (" +
> " price " +
> ") VALUES ('" +
> thePrice +
> "')";
>
> //String query = "UPDATE parkingPrice SET " +
> //"Price= thePrice ;
>
> System.out.println("query "+ query);
> //statement.executeUpdate( query );
> //statement.executeQuery( query );
> int rows = statement.executeUpdate( query );
> }
> }
>
> The variable thePrice is taken from a jsp page and the function just takes
> the value "price" and assigns it to thePrice;
> public void setPrice( String price ) {
> thePrice = price;
> }
>
> Any ideas,
> Thanks in advance, Mick
>
> ----Original Message Follows----
> From: "Clayton Peirens" <[EMAIL PROTECTED]>
> Reply-To: [EMAIL PROTECTED]
> To: <[EMAIL PROTECTED]>
> Subject: Re: SIMPLE SQL QUERY.....
> Date: Sun, 11 Mar 2001 08:14:27 -0700
>
> For your insert, replace
> statement.executeQuery( query );
> with
> int rows = statement.executeUpdate( query );
>
> It has nothing to do with result sets. An "update" can consist of INSERT,
> UPDATE, DELETE, and will return the number of rows affected by the SQL
> statement. The only time you need to worry about result sets is when
doing
> a SELECT, and then the executeQuery method would be appropriate.
>
> With regards to the UPDATE not affecting the DB, are you closing the
> statement, and the connection? Are you in "autocommit" mode?
>
> Hope this helps,
> Clayton
>
> ----- Original Message -----
> From: "Mick Sullivan" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: March 11, 2001 5:43 AM
> Subject: SIMPLE SQL QUERY.....
>
>
> > Hi
> > Can anyone help me with a simple SQL update query.
> > When I insert a value into my DB using the INSERT INTO statement I have
> no
> > problem.
> >
> > Statement statement = connection.createStatement();
> >
> > String query = "INSERT INTO parkingPrice (" +
> > " price " +
> > ") VALUES ('" +
> > thePrice +
> > "')";
> > statement.executeQuery( query );
> >
> > However I dont want multiple rows so when I try and do an update
instead
> > using the following:
> >
> > String query = "UPDATE parkingPrice SET " +
> > "Price='" + thePrice + "'";
> >
> > System.out.println("query "+ query);
> > statement.executeUpdate( query );
> >
> > There is no affect on the DB. I get no SQL errors and in the tomcat
> window
> > using the line "System.out.println("query "+ query);"
> > The query UPDATE parkingPrice SET Price='5'
> > The query seems valid yet there is no affect on the DB.
> > I am using MS ACCESS. Is the problem in the way the DB is set up?
> > Thanks in advance, Mick
> >
> >
_________________________________________________________________________
> > Get Your Private, Free E-mail from MSN Hotmail at
http://www.hotmail.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, email: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>
>
> _________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, email: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]