Saturday, July 16, 2016

program by using JDBC to execute an update query without using PreparedStatement and display the results

Aim: Write a program by using JDBC to execute an update query without using PreparedStatement and display the results.



Program: 

import java.sql.*;
import java.util.*;
class Update1
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c =DriverManager.getConnection("jdbc:odbc:xe","system","swapna");
Statement st= c.createStatement();
int a=st.executeUpdate("update student36 set name='swapna' where num=11"); System.out.println("\n\nUpdated\n\n");
st= c.createStatement();
ResultSet r1=st.executeQuery("select *from student36");
while(r1.next())
{
int x = r1.getInt("NUM");
String y= r1.getString("NAME");
System.out.println(x+"\t "+y);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}


Output:




Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home