how can connection with oracle10g with java

Answer Posted / dipanshu

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.sql.ResultSet;

public class Driver4Test
{
public static void main(String[] Dipanshu)throws SQLException

try
{
//Loading the Driver Class Class.forName("oracle.jdbc.driver.OracleDriver");

// creating the Connection obj to takl to Db
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:XE","USERNAME", "PASSWORD");

//create the Statement obj for sending and execute the query
Statement st=con.createStatement();

//Framing the Query with variable called sql
String sql="Select * from student";

//Sending and processing the query to DB
ResultSet rs=st.executeQuery(sql);

}
catch(Exception ex) {
System.out.println(ex.getMessage());
return null;
}
//Printing the results
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+getString(3);
}
//Closing the Objects
rs.close();
st.closee();
con.close();

}

This is the perfect Jdbc Application

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is jdbc thin client?

500


What is odbc jdbc?

533


How can we maintain the integrity of a database by using jdbc?

533


What are common JDBC Exceptions?

544


Is jdbc an api?

502






Which jdbc drivers will run your program?

510


What are restrictions on triggers?

1669


What is an encrypted internet connection?

499


How do I insert an image file (or other raw data) into a database?

519


What driver should I use for scalable Oracle JDBC applications?

498


What is jsp and jdbc?

491


What are the factors that the jdbc driver performance depends upon?

518


What is addbatch jdbc?

531


What is new in JDBC 2.0?

569


What is a statement in java?

511