Satement Querys || execute() || executeUpdate()|| executeQuery()

Published: 20 July 2021
on channel: KD_Tarpara
250
8

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());
}
}

}


On this page of the site you can watch the video online Satement Querys || execute() || executeUpdate()|| executeQuery() with a duration of online in good quality, which was uploaded by the user KD_Tarpara 20 July 2021, share the link with friends and acquaintances, this video has already been watched 250 times on youtube and it was liked by 8 viewers. Enjoy your viewing!