Home Answers Viewqa JDBC JDBC Connection code to connect servlet with oracle.

 
 


Abhay kathwate
JDBC Connection code to connect servlet with oracle.
1 Answer(s)      2 years and 5 months ago
Posted in : JDBC

JDBC Connection code to connect servlet with oracle

View Answers

January 5, 2011 at 12:54 PM


Hi Friend,

Follow these steps:

1) Import the following packages in your servlet file:

import java.sql.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;

2) Load and Register the JDBC driver:

   DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

or you can use

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

3) Connect to database:

a) If you are using oracle oci driver,you have to use:

Connection conn = DriverManager.getConnection("jdbc:oracle:oci8:
@oracle.world", "root", "root");

where oracle.world is the TNSNAMES entry and root is the username and password.

b) If you are using oracle thin driver,you have to use:

Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@localhost:3306:roseindia",
"root", "root");

where localhost is the host,3306 is the port, roseindia is the database and root is the username and password.

4) Querying the database:

a)create statement:

Statement st = conn.createStatement();

b)write query and execute the query:

ResultSet rs = st.executeQuery("SELECT * from student");

5) Close the statement,resultset and connection:

rs.close();
st.close();
conn.close();

Try the following code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;

public class Data extends HttpServlet { 
    public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
        String msg=req.getParameter("msg");
        res.setContentType("text/html");
        PrintWriter out = res.getWriter();
        System.out.println(msg);
        try {
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost:3306:Oracle", "rose", "rose");
    Statement stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery("select * from data");
    while(rs.next()){
        out.println(rs.getString("name")+"  "+rs.getString("address")+"<br>");
    }
        con.close();
        } 
        catch(Exception e){
        System.out.println(e);
        }
        }
        }

Thanks









Related Pages:
JDBC Connection code to connect servlet with oracle.
JDBC Connection code to connect servlet with oracle.  JDBC Connection code to connect servlet with oracle
Could not establish the connection to oracle - JDBC
to use: Connection conn = DriverManager.getConnection("jdbc:oracle:oci8... to use: Connection conn = DriverManager.getConnection ("jdbc:oracle:thin... oracle.jdbc.driver.OracleDriver()); Connection conn = DriverManager.getConnection("jdbc:oracle
JDBC Connection code to connect servlet with SQL Server 2008
JDBC Connection code to connect servlet with SQL Server 2008  Please ans me why it is not connect i use netbeans IDE7.0 Jdk 1.7 i also add... connection code is static Connection con; static Statement st; static
REQ for connection b/w jdbc and oracle database
REQ for connection b/w jdbc and oracle database    REQ for connection b/w jdbc and oracle database    The Java classes to connect...()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost
ex. connect to Oracle - Java Beginners
ex. connect to Oracle  dear sir, I want to ask how to connect java to oracle, please give me a details tutorial with example code how to connect..."; String db = "XE"; String url = "jdbc:oracle:thin:@" + serverName
error oracle database connection?
error oracle database connection?  hi now i am trying to connect oracle database and also insert my data into table, but it's not working.. I created... in oracle table. my table name is logininfoclient_sla. this is my coding
java connecting to oracle db - JDBC
to use: Connection conn = DriverManager.getConnection("jdbc:oracle:oci8... have to use: Connection conn = DriverManager.getConnection ("jdbc:oracle:thin...()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost
Java vs Oracle Connectivity - JDBC
connection with oracle database?  Hi Friend, Use Oracle with Java... are using oracle oci driver,you have to use: Connection conn = DriverManager.getConnection("jdbc:oracle:oci8: @oracle.world", "root", "root"); where
servlet - JDBC
about oracle.I am giving this code below please connect this code from sql... = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle","scott... con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracle
How to connect to database to my application if the database is made up in oracle
:*** a) If you are using oracle oci driver,you have to use: Connection conn = DriverManager.getConnection("jdbc:oracle:oci8: @oracle.world", "root", "root"); where... are using oracle thin driver,you have to use: Connection conn
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data..
Unable to connect servet, jsp to oracle 10g database.. Unable to retrieve data...= driver=oracle.jdbc.driver.OracleDriver url=jdbc:oracle:thin:@192.168.100.20.... If I use it also, unable to connect to backend oracle database. Let me
jdbc oracle connectivity problem
jdbc oracle connectivity problem  Hi All, I am trying to connect my swing application to oracle DB . but class.forname is giving error. Please suggest me if there is some different way to connect swing application to oracle
how to connect mysql with JDBC - JDBC
in the database MYsql, i have to connect them now using JDBC, can u please suggest me... { connection = DriverManager.getConnection("jdbc:mysql://localhost...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
connect jdbc to an Excel spreadsheet
connect jdbc to an Excel spreadsheet  hello, How can I connect to an Excel spreadsheet file using jdbc?   Hello Friend, Follow..."); Connection conn = DriverManager.getConnection("jdbc:odbc:excel
jdbc connection to java program code - JDBC
jdbc connection to java program code  i want a simple java program that which communicates with oracle database like creating table,insert values and update records in database and show in program output? please take a simple
i can not connect to database in servlet - JSP-Servlet
offer .   Hi friend, Code to connect to database in servlet... the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting...(""); out.println("Servlet JDBC"); out.println(""); out.println("Servlet JDBC
i can not connect to database in servlet - JSP-Servlet
offer .   Hi friend, Code to connect to database in servlet... the tutorial in this site on servlet and JDBC. I did all the proccedure for connecting..."); PrintWriter out = response.getWriter(); out.println(""); out.println("Servlet JDBC
JDBC Oracle program
JDBC Oracle program  Here is my code: import java.sql.*; public...("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:oracle", "System", "System
how to connect swings with jdbc... - Java Beginners
how to connect swings with jdbc...  Hi friends, Is it possible, to connect swings with data base like oracle....i want to store data into database... purpose , i want to use oracle 8 or 9........ can any one explain me with example
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
jsp connection with oracle.
jsp connection with oracle.  I want to connect with jsp to oracle,,,plz send me the codes
server database connection - JSP-Servlet
"); 2.Connection con=DriverManager.getConnection("jdbc:odbc:Driver={Microsoft ODBC For Oracle}","scott","tiger"); But how to get the connection from...server database connection  sir generally we will connect
jdbc connection issues
in the database correspondingly. How pls tell me how connect these 11 forms and 11 tables with only one jdbc connection program...if possiable pls post a sample code...jdbc connection issues  Hello. kindly pls help in this issue...i
Oracle Database error - JDBC
Oracle Database error   String query11 = "SELECT product_code... = stmt.executeQuery(query11); while(rs11.next()){ product_code[j] = rs11.getString("product_code"); product_quantity[j
Server DB connection - JDBC
also tried passing the 4th argument to the mysql_connect function but I can't get it to work. If you have any sample code for getting connection please...Server DB connection  Hello Guys I want to connect two databases
JDBC connection
to understand JDBC connection. The code explains you   how... Jdbc Connection, We have a list of method required to connect and close... JDBC connection       The JDBC
DataBase Connection
DataBase Connection  How to connect java and Oracle 10g? Tell me Jdbc connection
how to write a code for oracle database connection in asp.net for validation.
how to write a code for oracle database connection in asp.net for validation...:\oracle\product\10.2.0\client_1\BIN directory. This directory may be different based on your oracle configuration. using Oracle.DataAccess.Client; // C
JDBC connection and SQL Query - JDBC
JDBC connection and SQL Query  Hi, I'm reading a all files one... each time. Now I'm trying to execute a query to insert those values into an oracle... to make it. even the code i wrote below has some error with quotation marks
java to oracle code - JDBC
java to oracle code  please suggest m calculate the database performance between scaled images and unscaled images in the database
Java Connection to Oracle database
Java Connection to Oracle database  HI I am ubable to connnect jdbc to Oracle database.i had gone to control panel >>Administrative tool>>>Data source,in that forDNS name i typed Oracle and in TNS i culdn't
JDBC Connection and Registration
JDBC Connection and Registration   How to create a JDBC connection... your java with jdbc code.. It will create table in MS access database. Here..... :-)   JDBC MS Access Database Connectivity: Follow these steps: 1)Go
java database connection - JDBC
{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection connect =DriverManager.getConnection("jdbc:odbc:access"); pstm=connect.prepareStatement("insert into data... so..  Hi Friend, We are providing you a code that will insert
oracle - JDBC
oracle  HI i am using ORACLE 10g. How to i find "TNSNAMES.ORA" file in my system after installation of ORACLE 10g succussfully. please send... that depends on the actual network implementation used. Oracle recommends that SDU
android connection to database oracle 10g
android connection to database oracle 10g  Hello, How i can connect my android application to my oracle 10g database
Oracle Database connectivity probem
Foundation\Tomcat 6.0\lib\servlet-api.jar;E:\oracle\ora81\jdbc\lib\classes111.zip I... ("oracle.jdbc.driver.OracleDriver"); Connection conn = DriverManager.getConnection("jdbc:oracle:thin...Oracle Database connectivity probem  hi Below is the code of oracle
JDBC Connection Pool
database connection in resource pool. You can make your own code for JDBC...JDBC Connection Pool In this section we will learn about JDBC Connection Pool... application will give you improved performance if you use the JDBC Connection
connection - JDBC
connection  how to connect server pages to mysql  Hi Friend, To learn how to connect MySql to JSP, please visit the following link: http://www.roseindia.net/jsp/connect-jsp-mysql.shtml Thanks
JDBC - JDBC
()); Connection conn = DriverManager.getConnection("jdbc:oracle:thin: @localhost...JDBC  how can i do jdbc through oracle.. pls if u can send me d.... thanking u santosh.  Hi Friend, Use JDBC with Oracle Follow
jdbc - JDBC
"); 3) Connect to database:*********** a) If you are using oracle oci driver,you have to use: Connection conn = DriverManager.getConnection("jdbc:oracle...jdbc   kindly give the example program for connecting oracle dase
JDBC - JDBC
Connect Example."); Connection conn = null; String url = "jdbc:mysql...JDBC  i am goint to work on JDBC and i knew oracle but very poor in java is it possoble to me to do JDBC is it so please give me SOME SAMPLE
oracle connectivity
oracle connectivity  con=DriverManager.getConnection("jdbc:oracle... following code Connection con; Statement stmt; try...=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","hr","hr
storing date from html form to oracle 10g using servlet
"); con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","ORS","ors"); // code for inserting date into oracle 10g in the format of oracle... the data in oracle you need to follow the jdbc concept. here is the snippet
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS. But it has
About connection database oracle to java
About connection database oracle to java  **Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to java
About connection database oracle to java  Hi I culdn't connect oracle datebase to java.when i compile the program it is ok.but when i clicked... Oracle and then i clicked add button.Then Dialog box came indicating DNS and TNS
About connection database oracle to java
About connection database oracle to java   I culdn't connect oracle... Panel>>Administrative Tools>>Data Sources in that i selected Oracle... just typed DNS as Oracle and for TNS i clicked on the list of TNS .But it has
cannot connect to database - JDBC
cannot connect to database  Iam using eclipse in my system ,when connecting the database mysql version 5.0 to the eclipse iam getting an error as ""Creating connection to mysql has encountered a problem.Could not connect to mysql
how can i create a mysql database to connect to this code - JDBC
"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register...("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc..."); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register