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
What is the different between ResultSet and RowSet?
How can I write to the log used by DriverManager and JDBC drivers?
What is represented by the connection object?
RowSetInternal caller and returns void. What can I do in the readData method?
What is JDBC RowSet? What are different types of RowSet?
In which ways is driver class is registered with drive manager?
How can I know when I reach the last record in a table, since JDBC doesn't provide an EOF method?
Explain the difference between rowset vs. Resultset in jdbc?
What are the differences between execute, executequery, and executeupdate?
What packages are used by jdbc?
Why do I have to reaccess the database for Array, Blob, and Clob data?
What is odbc and jdbc?
What is jdbc connection interface?
What are the components of jdbc?
Explain how data flows from view to db and reverse