Prepared_Statement_Demo.java code Google Drive link :
https://drive.google.com/file/d/15uL-...
Prepared_Statement_Demo.java code :
import java.sql.*;
public class Prepared_Statement_Demo {
public static void main(String[] args) {
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Class/Driver Loaded");
String url="jdbc:mysql://localhost:3306/hjd";
String user="root";
String pass="";
Connection conn = DriverManager.getConnection(url,user,pass);
System.out.println("Conncetion Doned");
// String SQLInsert="insert into student values(?,?,?)";
// PreparedStatement pst=conn.prepareStatement(SQLInsert);
// pst.setInt(1,101);
// pst.setString(2,"Studentupdated");
// pst.setString(3,"jamanger");
// String SQLUpdate="update student set scity=?,sname=? where sno=?";
// PreparedStatement pst=conn.prepareStatement(SQLUpdate);
// pst.setString(1,"Studentupdated");
// pst.setString(2,"jamanger");
// pst.setInt(3,101);
// String SQLDelete="delete from student where sname=?";
// PreparedStatement pst=conn.prepareStatement(SQLDelete);
// pst.setString(1,"jamanger");
//int n=pst.executeUpdate();
String SQLSelect="select *from student";
PreparedStatement pst=conn.prepareStatement(SQLSelect);
ResultSet rs=pst.executeQuery();
System.out.println("SNO\tSNMAE\t\tSCITY");
while(rs.next())
{
System.out.println(rs.getInt(1)+"\t"+rs.getString(2)+"\t"+rs.getString(3));
}
//System.out.println("Row Efectted : "+n);
rs.close();
pst.close();
conn.close();
}
catch(Exception e)
{
System.out.println("Error : "+e.toString());
}
}
}