VIKAS JANGID JERTHI
Vikas Jangid Jerthi Sikar Rajasthan
JDBC (Java DataBase Connectivity Program) at RAT Jaipur
JDBC (Java DataBase Connectivity Program)
import java.sql.*; import java.util.Scanner; public class MySql { public static void main(String args[]) { try { System.out.println("My Sql connect example"); Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/college","root","system"); Statement stmt=con.createStatement(); Scanner sc=new Scanner(System.in); System.out.println("Please Enter sid"); String sid=sc.nextLine(); System.out.println("Please Enter sname"); String sname=sc.nextLine(); String str="insert into student values('"+sid+"','"+sname+"')"; stmt.executeUpdate(str); System.out.println("record inserted successfully... Total Values are"); String strr="select * from student"; ResultSet res=stmt.executeQuery(strr); while(res.next()) { System.out.println(res.getInt(1) +":"+ res.getString(2)); } }catch(Exception e){ e.printStackTrace(); } } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment