Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

import java.sql.

*;
public class DB {

public static void main(String[] args) {


// TODO Auto-generated method stub
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection c=
DriverManager.getConnection("jdbc:Oracle:thin:@localhost:1521:xe","system","system");
System.out.println("connect....");
Statement s = c.createStatement();
//s.executeUpdate("create table std(nmae varchar2(25),pass varchar2(30))");
//int x= s.executeUpdate("insert into std values('ram','123')");
// System.out.println(x + " rec is inserted");
String s1 ="Rohan";
String s2 ="Rai";
// s.executeUpdate("insert into std values('"+s1+"','"+s2+ "')");
PreparedStatement ps;
ps = c.prepareStatement("insert into std values(?,?)");
ps.setString(1,s1);
ps.setString(2, s2);
ps.executeUpdate();

ResultSet rs = s.executeQuery("select * from std");


while(rs.next())
{
System.out.println(rs.getString(1)+"\t" +rs.getString(2));

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

You might also like