Monday, January 13, 2014

ava JDBC programming Example 10

//Note: create  a DSN in the name of sql that is pointing the table name limbs in the database with three String column  names things,legs,arms




//PreparedStatement  update sql
import java.sql.*;
class Jdbc10{
public static void main(String...arg) throws Exception{
         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
         Connection c =  DriverManager.getConnection("jdbc:odbc:sql");
         PreparedStatement pstmt = c.prepareStatement
                                  ("update limbs set legs =? where arms =?");
         pstmt.setInt(1,5); //legs 8
         pstmt.setInt(2,0);
        int i = pstmt.executeUpdate();
        System.out.println("No of records updated    :"+i);
       
     
      pstmt.close();
      c.close();
}
}

No comments: