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
How to make updates to updatable result sets in jdbc?
Is jdbc a web technology?
Explain the role of driver in jdbc.
What is jdbc driver for sql server?
Write an sql to find all records having all upper case alphanumeric characters in a field ?
What is jdbc and jpa?
How does a custom RowSetReader get called from a CachedRowSet?
Write an sql to find all records having all numeric characters in a field ?
What is ojdbc?
What is phantom read and which isolation level prevents it?
What are the flow statements of jdbc?
Expalin the method of calling a stored procedure from jdbc.
What is the role of jdbc drivermanager class?
What does jdbc do?
What are common JDBC Exceptions?