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 advantage of namedparameterjdbctemplate?
What is meant by jdbc and odbc?
How do I set properties for a JDBC driver and where are the properties stored?
What is @entity in java?
How the JDBC application works?
What does the jdbc driver interface do?
What is resultsetmetadata?
What are the different types of statements? How we can you use preparedstatement.
Name the types of jdbc drivers.
What packages are used by jdbc?
How to use JDBC to connect Microsoft Access?
Which interface handles transaction management in jdbc?
What are the advantages of using preparedstatement over statement?
Where can I find ojdbc14 jar file?
How does a file store compare with a jdbc store?