how can connection with oracle10g with java

Answers were Sorted based on User's Feedback



how can connection with oracle10g with java..

Answer / rajshri

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con=DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:XE", "system", "system");
//(system,system is username and passward of oracle 10g)

Statement st=con.createStatement();

String sql="(here your sql statement must be of select
pattern)";

ResultSet rs=st.executeQuery(sql);

while(rs.next())
{
AND SO ON...

Is This Answer Correct ?    33 Yes 4 No

how can connection with oracle10g with java..

Answer / kishan

package dao;
import java.sql.Connection;
import java.sql.DriverManager;
public class Database {
static final String USERNAME="hr";
static final String PASSWORD="hr";

public static Connection getConnection()
{
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:XE",
USERNAME, PASSWORD);
return con;
}
catch(Exception ex) {
System.out.println(ex.getMessage());
return null;
}
}
}

Is This Answer Correct ?    6 Yes 2 No

how can connection with oracle10g with java..

Answer / 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

More JDBC Interview Questions

What is thin driver in jdbc?

0 Answers  


Give an example for execution of sql statement.

0 Answers  


What is an advantage of using the jdbc connection pool?

0 Answers  


How can you make the connection using jdbc?

0 Answers  


What is the jdbc rowset?

0 Answers  






What are stored procedures? How to call them?

3 Answers  


write a query to select name from one table which has id,name and salary from another table which has id, sal where the salary is the second maximum

3 Answers   Bosch, HireCraft, Infosys,


What are the Isolation level in JDBC transaction?

1 Answers  


any one can explain about policy file rule? when i connect database with applet then ther is no compile time error but the run time error is occureed.i.e access is denied.policy file rule is related to this problem.

0 Answers  


What is jdbc databasemetadata interface?

0 Answers  


Why do I get UnsatisfiedLinkError when I try to use my JDBC driver?

0 Answers  


What are static and dynamic queries?

1 Answers  


Categories