Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 the different between ResultSet and RowSet?

1065


How can I write to the log used by DriverManager and JDBC drivers?

1050


What is represented by the connection object?

1127


RowSetInternal caller and returns void. What can I do in the readData method?

1020


What is JDBC RowSet? What are different types of RowSet?

1127


In which ways is driver class is registered with drive manager?

956


How can I know when I reach the last record in a table, since JDBC doesn't provide an EOF method?

1036


Explain the difference between rowset vs. Resultset in jdbc?

1038


What are the differences between execute, executequery, and executeupdate?

992


What packages are used by jdbc?

995


Why do I have to reaccess the database for Array, Blob, and Clob data?

1137


What is odbc and jdbc?

1077


What is jdbc connection interface?

1075


What are the components of jdbc?

1031


Explain how data flows from view to db and reverse

2085