Required Jar files
1) Mysql-connector.jar(for connecting MYSQL DB)
2) Ojdbc14.jar(for Oracle DB)
Java File Name - DBRecordDelete.java
package com.jdbc;
import java.sql.DriverManager; import java.sql.SQLException; import com.mysql.jdbc.Connection; import com.mysql.jdbc.PreparedStatement; /** * @Author -- Ramu Chintha */ public class DBRecordDelete { public static void main(String[] args) throws SQLException { Connection con=null; PreparedStatement pstmt = null; try{ Class.forName("com.mysql.jdbc.Driver"); con = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/learnjava","root","ramu"); String sql ="DELETE FROM VIDEO_TABLE WHERE ID =3"; pstmt = (PreparedStatement) con.prepareStatement(sql); pstmt.execute(); System.out.println("Record is deleted sucessfully"); } catch(Exception e){ e.printStackTrace(); } finally{ if(con != null){ con.close(); } } } } |




0 comments:
Post a Comment