Update Query

I am connected to a database and trying to update a table, wiht a value in a similar field, based on it's null values. I keep getting and error that says syntax error in update statement. This is my first time trying this my code is below any suggestions?

import java.sql.*;

public class CoalTotals {

public static void main(String[] arguments) {

int count=0;

String data = "jdbc:odbc:OSBUpdate";

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn = DriverManager.getConnection(

data, "", "");

Statement st = conn.createStatement();

ResultSet rec = st.executeQuery(

"SELECT LoanNumber, CancellationDate, PayoffDate " +

"FROM [AllFixedLoansNoNull] " +

"WHERE " +

"(PayoffDate is null) " +

"ORDER BY LoanNumber");

while(rec.next()) {

ResultSet updat = st.executeQuery(

"Update [AllFixedLoansNoNull]"+

"(Set PayoffDate = '"+rec.getString(2)+"') "+

"WHERE "+

"(LoanNumber='"+rec.getString(1)+"')");

System.out.println(rec.getString(1) + "\t"

+ rec.getString(2) + "\t\t"

+ rec.getString(3));

}

System.out.println(count);

st.close();

} catch (SQLException s) {

System.out.println("SQL Error: " + s.toString() + " "

+ s.getErrorCode() + " " + s.getSQLState());

} catch (Exception e) {

System.out.println("Error: " + e.toString()

+ e.getMessage());

}

}

}

[1499 byte] By [JLIZ2803a] at [2007-10-2 3:08:38]
# 1
If you have a null value, most JDBC drivers require you to call setNull() rather than setXXX().- Saish
Saisha at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...
# 2
Also, when posting, please format your code with the 'code' button above.- Saish
Saisha at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...
# 3

I am updating null values, null values are being replaced with string values. below is the code I have it runs but instead of updating the database I the ldb fiel gets created and nothing gets updated

import java.sql.*;

import java.util.*;

public class CoalTotals {

public static void main(String[] arguments) {

int count=0;

String Pdate;

String Loan;

String data = "jdbc:odbc:OSBUpdate";

try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

Connection conn = DriverManager.getConnection(

data, "KTURNOCK", "admin");

Statement st = conn.createStatement();

ResultSet rec = st.executeQuery(

"SELECT LoanNumber, CancellationDate, PayoffDate " +

"FROM [AllFixedLoansNoNull] " +

"WHERE " +

"(PayoffDate is null) " +

"ORDER BY LoanNumber");

while(rec.next()) {

Pdate = rec.getString(2);

Loan = rec.getString(1);

System.out.println(Loan + "\t"

+ Pdate + "\t\t"

+ rec.getString(3));

PreparedStatement pstmt = conn.prepareStatement(

("UPDATE [AllFixedLoansNoNull] SET PayoffDate = ? WHERE LoanNumber = ?"));

pstmt.setString(1, Pdate);

pstmt.setString(2,Loan);

}

st.close();

} catch (SQLException s) {

System.out.println("SQL Error: " + s.toString() + " "

+ s.getErrorCode() + " " + s.getSQLState());

} catch (Exception e) {

System.out.println("Error: " + e.toString()

+ e.getMessage());

}

}

}

JLIZ2803a at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...
# 4
You never call pstmt.executeUpdate().- Saish
Saisha at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...
# 5
Thank you so much a little detail I would have never seen, you have no idea how happy you just made me thanks again
JLIZ2803a at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...
# 6
Glad I could help. Best of luck.- Saish
Saisha at 2007-7-15 21:35:29 > top of Java-index,Administration Tools,Sun Connection...