In order to connect to oracle database you need to add ojdbc14.jar file in your eclipse project as a external jar file.... Download from web.
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class OracleConnect {
/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","saravanan","saravanan");
System.out.println("Connected Successfully To Oracle");
Statement stmt;
ResultSet rs;
stmt=con.createStatement();
rs=stmt.executeQuery("select * from saran");
while(rs.next())
{
System.out.println(rs.getString("empname")+"--"+rs.getInt("salary"));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
No comments:
Post a Comment
Please post your comments. Your comments make us to write more programs for you.