Database Table :
Example for Delete :
packagenewpackage;
importjava.sql.*;
public class
NewClass
{
public static void
main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:Database31");
Statement s=con.createStatement();
String query="Delete from
Table1 where ID=7";
s.execute(query);
String query1="select
*from Table1";
s.execute(query1);
ResultSetrs=
s.getResultSet();
while(rs.next())
{
System.out.print("
, Id :"+rs.getInt("ID"));
System.out.print("
, Name :"+rs.getString("name"));
System.out.println("
, No :"+rs.getInt("no"));
}
s.close();
con.close();
}
catch(Exception e)
{
System.out.print(" Exception : "+ e);
}
}
}
Output
:
Example for Update:
packagenewpackage;
importjava.sql.*;
public class NewClass
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=
DriverManager.getConnection("jdbc:odbc:Database31");
Statement s=con.createStatement();
String query="update Table1 set name='Ajeet',no=98765 where
ID=2";
s.execute(query);
String query1="select *from
Table1";
s.execute(query1);
ResultSetrs= s.getResultSet();
while(rs.next())
{
System.out.print(" , Id
:"+rs.getInt("ID"));
System.out.print(" , Name
:"+rs.getString("name"));
System.out.println(" , No
:"+rs.getInt("no"));
}
s.close();
con.close();
}
catch(Exception e)
{
System.out.print(" Exception : "+ e);
}
}
}
Output
:
No comments:
Post a Comment