JDBC Crud Operation Insert Multiple Records With Prepared Statement in Java

 package jdbc_pre_stmt;


import java.sql.Connection;

import java.sql.DriverManager;


import com.mysql.jdbc.PreparedStatement;


public class Jdbc_Pre_Stmt {

public static void main(String[] args) throws Exception{

Class.forName("com.mysql.jdbc.Driver");

System.out.println("Driver Loaded......");

Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/batch138","root","root");

System.out.println("Connection Success.....");

PreparedStatement pd=(PreparedStatement) cn.prepareStatement("insert into student values(?,?)");

pd.setInt(1, 301);

pd.setString(2, "Python");

pd.execute();

pd.setInt(1, 1010);

pd.setString(2, "Java");

pd.execute();

pd.setInt(1, 10);

pd.setString(2, "SQL");

pd.execute();

pd.setInt(1, 01);

pd.setString(2, "Dart");

pd.execute();

System.out.println("inserted......");

}


}

Comments

Popular posts from this blog

Primary/Main features of Java

HTTrack ऑफलाइन वेबसाइट डाउनलोडर क्या है ?

Which language is used for Java?