การเพิ่ม Libraries ของ oracle ลงใน Netbeans
หน้าแรก Netbeans การเพิ่ม Libraries ของ oracle ลงใน Netbeans
Before we can execute query on database we need connection , now we try to connecting JSP to Oracle DB XE.
First thing you need to prepare is ojdbc6.jar , you can get it on:
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
Second , you need to import this driver into the project
+ Project Properties (Right Click on Project name)
+ Categories » Choose Libraries (on Left Column)
+ Choose Compile tab
+ Click Add JAR/Folder
+ Locate where your ojdbc6.jar file
<%@ page import="java.sql.*" %>
// to import java sql , in this package is consist of basic funtion of SQL
Connection connection = null;
// to initialize connection
String driverName = "oracle.jdbc.driver.OracleDriver";
// to import oracle driver
Class.forName(driverName);
// to call method
connection = DriverManager.getConnection(url, username, password);
// this is login information for database
what mean of url ? username ? or password ? OK let see this one , this is example of url:
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
serverName : is ussualy localhost or 127.0.0.1 , if in different computer you can fill it with ip address of server
portNumber : on default is 1521 but may different on another computer depend on oracle database port configuration
sid : is database name , for Oracle Database XE , database name is XE
String url = "jdbc:oracle:thin:@ Localhost:1521:XE;
now example of full code connection :
<%@ page import="java.sql.*" %>
<%
Connection connection = null;
try {
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
String url = "jdbc:oracle:thin:@ Localhost:1521:XE;
String username = "web";
String password = "password";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
out.print("Upsss Your Driver ist found =)");
} catch (SQLException e) {
out.print("Something bad happended :O ");
}
%>
My Version :
Product Version: NetBeans IDE 7.0 (Build 201104080000)
Java: 1.6.0_18; OpenJDK Client VM 14.0-b16
System: Linux version 2.6.32-5-686 running on i386; UTF-8; en_US (nb)
Userdir: /home/okta/.netbeans/7.0
refer: http://oktarahadian.com/post/4881418107/get-connection-jsp-and-oracle-database-xe
ขึ้นไปด้านบน
