Books Related to Java Technology

Monday, January 5, 2009

JDBC Update Query Example



import java.io.*;
import java.sql.* ;

class JDBCUpdate{
public static void main( String args[] ){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dbName","root", "root") ;
Statement stmt = conn.createStatement() ;
int rows = stmt.executeUpdate("UPDATE tableName SET columnName='' WHERE columnName=''") ;
System.out.println(rows + " Rows modified") ;
stmt.close() ;
conn.close() ;
} catch(SQLException se) {
System.out.println("SQL Exception:"+se) ;
} catch(Exception e){
System.out.println(e) ;
}
}
}

No comments:

Post a Comment