This is a discussion on oracle database connectivity within the Java Tutorials forums, part of the Articles and Tutorials category; Hi all can any one tell me , how to connect the database in java? Is there any need to set ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Re:oracle database connectivity
Oracle Corporation has released a free 100% JAVA driver. It is available at their Web site. According to the security rule, the Oracle server must be on the same machine as the Web server, since the communication with the Applet is done through Sockets. This is not always possible, so you will need something called a Connection Manager (from Oracle) or DBAnywhere from Symantec (demo version available for testing) to act as a bridge between the client, the Web server and the Database server.
Script sample : import java.sql.*; public class connectToOracle extends java.applet.Applet { Driver driver; Connection conn = null; static String driverUsed = \"oracle.jdbc.driver.OracleDriver\"; static String serverAddress = \"jdbc racle:thin:scott/tiger@www.myCompany.com:1243:myInstance\";// jdbc racle:thin is the driver used// scott/tiger is user/password // www.myServer.com is the same machine from where the Applet was loaded // 1234 is the port used // myInstance is where my data is public void init(){ makeConnection(serverAddress); } public void makeConnection(String svr) { try { System.out.println(\"Loading ... \" + driverUsed); driver = (Driver)Class.forName(driverUsed).newInstance(); System.out.println(\"Connecting ... \" + svr); conn = DriverManager.getConnection(svr); System.out.println(\"Ready.\"); } catch (Exception e) { e.printStackTrace(); } } } Please read the tutorial below to understand how this works... http://www.caucho.com/products/resin/ref/db-config.xtp |
|
|||
|
Here are few links.....
http://www.awprofessional.com/articl...&seqNum=6&rl=1 e236. Connecting to a MySQL Database This example connects to a MySQL database using the MM JDBC driver for MySQL. You need to have an account in MySQL database to run this example. To create an account, you can connect to MySQL database on your platform as root, and run the following command: mysql> GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY 'password' WITH GRANT OPTION; Connection connection = null; try { // Load the JDBC driver String driverName = "org.gjt.mm.mysql.Driver"; // MySQL MM JDBC driver Class.forName(driverName); // Create a connection to the database String serverName = "localhost"; String mydatabase = "mydatabase"; String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url String username = "username"; String password = "password"; connection = DriverManager.getConnection(url, username, password); } catch (ClassNotFoundException e) { // Could not find the database driver } catch (SQLException e) { // Could not connect to the database } |
|
|||
|
oracle data base connectvity
import java.sql.*;
class Appl { public static void main(String args[])throws Exception { Driver d=new oracle.jdbc.driver.OracleDriver(); //register to driver DriverManager.registerDriver(d); //connect to oracle data base Connection c=DriverManager.getConnection("jdbc racle:thin:@localhost:1521 rcl",scott","tiger");Sysem.out.println("connecting to Oracle Database.........."); Sysem.out.println("connected to Oracle Database"); } } |
![]() |
| Thread Tools | |
|
|