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

How can you make a connection?

712


What is JDBC Transaction Management and why do we need it?

727


What are the steps to connect to a database in java?

675


Why did my jdbc code throw a rollback sqlexception?

663


How does a file store compare with a jdbc store?

849


Differentiate between a statement and a preparedstatement.

680


What is the limitation of PreparedStatement and how to overcome it?

839


Explain the JDBC Architecture?

781


Does the JDBC-ODBC Bridge work with Microsoft J++?

2050


Explain the difference between rowset vs. Resultset in jdbc?

760


When do we use execute method in java jdbc?

708


Result set’s index starts with 0 or 1?

739


What is use of connection pooling?

711


Where can I find ojdbc14 jar file?

689


What are the jdbc api components?

866