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 many types of statements are there in jdbc?
How many rowset are available in jdbc?
What are the advantages of using jdbc datasource?
What do you mean by metadata and why we are using it?
What are the flow statements of jdbc?
Is jdbc faster than odbc?
What is isolation level? How to set it?
What is the JDBC syntax for using a literal or variable in a standard Statement?
What is createstatement method in java?
What are the classes and methods used for sending sql statements to database?
Why do you use a data source object for a connection?
What is jdbc thin client?
What is a lock in jdbc?
What is two-phase commit in the database?
What are dml and ddl?