Statement_Demo.java Code googleDrive Link :
https://drive.google.com/file/d/1U7yw...
Statement_Demo.java Code :
import java.sql.*;
public class 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");
Statement stmt =conn.createStatement();
System.out.println("Statement Created");
int sno=2;
String sname="KD";
String scity="Surat";
String SQLInsert="INSERT INTO student(sno,sname,scity) VALUES ("+ sno +",'" + sname + "',' "+ scity +"')";
int n = stmt.executeUpdate(SQLInsert);
// String SQLUpdate ="update student set sname='KDupdated' where sno=101";
// int n = stmt.executeUpdate(SQLUpdate);
// String SQLDelete ="Delete from student where sname=sname";
// int n = stmt.executeUpdate(SQLDelete);
String SQLSelect="select *from student";
ResultSet rs=stmt.executeQuery(SQLSelect);
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();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println("Error : "+e.toString());
}
}
}