- Start the First(Start->All Programs->Oracle with version->Start Database)
Navigate to Services tab.
If services tab is not available ,press ctrl+5 or go to windows menu.Double click the Drivers folder
You can see there is Oracle Thin option.
Right click on Oracle Thin ,then select Connect Using
Now you can view small window.
Fill the form with following Details:
Host: localhostCopy the JDBC Url to notepad for feature usage.
Port: 1521
SID: XE
username: system
Password: password which you gave when installing oracle.
Check show JDBC url
Refer this Picture ,if you have doubt:
Now you can see the option which start with "jdbc:oracle"
Right click on that. If the connection is not established,click "connect"
Now let's check whether the connection is established or not.(make sure the oracle database is started).
Right click on jdbc:oracle:thin:@localhost:1521:XE
Select Execute Command.
In Right Panel ,type your command.
For checking purpose just create one table.
For Eg:
create table EMP number);Press ctl+shift+E for executing the command
Checking in oracle Database:
Let's check further whether the table is created in Oracle database or not.
Start->AllPrograms->Oracle->GoTo Database HomePage
Now you can see oracle login page .
Enter the username as system
Enter the password which you gave when installing oracle Database.
Now you can see this:
Select SQL.
New page will be loaded. Select SQL commands.
Now run this command for checking whether the table is created or not.
desc table_name;In our example we create students table. so the command is "desc EMP”
f you get the structure of table,good..!!!connection working perfectly.
If the output is "undefined" ,check the whether you followed correctly my instruction.
Stage II
we successfully connect the oracle with netbeans. Now what ? We have to connect the database in servlet.
Create New Servlet.
import sql package.
import java.sql.*;insert the following code in try block which is in processRequest function.
Class.forName("oracle.jdbc.OracleDriver");
After the above code paste this code:
Connection con=DriverManager.getConnection(jdbc:oracle:thin:@localhost:1521:XE","system","Password");
change the Password with your oracle database password.
Now add this code :
out.println("Connection Established");Create Catch Block with SQLException.if you don't know how to create just paste the following code between the try and finally black:
The final code will be :
catch(SQLException e)
{
out.println(e.toString());
}
catch(Exception e)
{
out.println(e.toString());
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Class.forName("oracle.jdbc.OracleDriver");
Connection con =DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","system","adminadmin");
out.println("connection established");
}
catch(SQLException e)
{
out.println(e.toString());
}
catch(Exception e)
{
out.println(e.toString());
}
finally {
out.close();
}
}
Now add Ojdbc driver.
Right click on the project.
Select Properties.
Click the Libraries tab.
click the add jar /folder option
Navigate to this Path in that window:
C:\Program Files\Java\jre1.6.0\libYou can see there is
ojdbc6_2.jar fileNote: If you didn't have just download from oracle.com. Use jdk1.6 .
open ojdbc6_2.jar file.
That's all run the project. and move to Servlet url. You can see "connection established" text .
can u refer which is best approach to connect database using middleware services.
ReplyDeleteThere are several types of middleware services.
ReplyDelete1.Remote Data Access (RDA), which implements a RDA protocol for sending data manipulation language statements to an appropriate database server for processing and transporting the result back to the invoking process.
2.Remote procedure calls (RPCs). RPC is used in most network operating system services.
3.Message-oriented middleware (MOM). MOM can be used as a mechanism for storing and forwarding messages queuing.It can be used when client and server processes communicate asynchronously.
4.Object Request Brokers(ORBs). A standard implementation of the ORB standard is CORBA. ORB makes it possible to invoke a remote object by allowing a source object to send a message to that remote object.
5.Distributed transaction processing (DTP). This type of mechanism use execution semantics to interact between the client and the server.