Connection of Java applications to Database
Can you provide me some information about connection of java application to database and what are the stuff should be available to build this project. I want to use oracle database and for oracle which type of driver would be used.I am confused to use the provided drivers for java application.which type of driver would be used for different java applications.I am so curious to know about the JServer and how it would be configure on my machine.
Connection of Java applications to oracle
Here is one example which will show you a demo to connection of an java application to oracle database,it uses JDBC driver for connection.
import java.sql.*;
class javatooracle
{
public static void main (String args []) throws SQLException
{
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection
("jdbc:oracle:thin:@hostname:1526:mydb", "Hr", "Hr");
// @IP address :portname:databaseID, userid,password
Statement stmt = conn.createStatement();
ResultSet rset = stmt.executeQuery("select BANNER from SYS.V_$VERSION");
while (rset.next())
System.out.println (rset.getString(1));
stmt.close();
}
}
JDBC in Java to Oracle connection
JDBC:
JDBC is simply a class and interface which is written in java language to execute those java program which is written to retrieve data from the database.
It accept the SQL statement from the program and access the data from database and returns to application.
Oracle database provides three types of JDBC driver:
1. JDBC Thin Driver is required for applets in java
2. JDBC OCI for simple and standalone applications in java
3. JDBC KPRB driver for stored procedure and java server pages
JServer in Oracle Database
JServer:
The oracle database facilitate to the java programmer a tool JServer Accelerator which speed up the code execution of java applications.
Configuring JServer:
1. Confirm, your instance should be started with more than 20M
of java_pool_size and 50M for shared_pool_size space for this configuration
2. execute the $ORACLE_HOME/javavm/install/initjvm.sql file with the sys account
3. Type the statement given below:
SQL> GRANT JAVAUSERPRIV TO SCOTT;
Now "scott" user can use this privilege to execute the script regarding JVM and follow the "Oracle Migrations Guide" to know more about this.