0% found this document useful (0 votes)
42 views1 page

Import Public Class Public Static Void Try

This Java code connects to an Oracle database, inserts user data into a table using a prepared statement, and then retrieves and prints the data. It establishes a connection to the database, inserts the values "Rohan" and "Rai" into the "std" table using a prepared statement, and then executes a query to select all data from the "std" table and print the results.

Uploaded by

Nikhat Bano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views1 page

Import Public Class Public Static Void Try

This Java code connects to an Oracle database, inserts user data into a table using a prepared statement, and then retrieves and prints the data. It establishes a connection to the database, inserts the values "Rohan" and "Rai" into the "std" table using a prepared statement, and then executes a query to select all data from the "std" table and print the results.

Uploaded by

Nikhat Bano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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