Connectivity : Mysql, Oracle and MS Access

subscribe-png-579

Connectivity : Mysql, Oracle and MS Access

  • For Oracle

Note :

You need this Jar File to Run JDBC and Connection :

download the jar file ojdbc14.jar
http://www.javatpoint.com/src/jdbc/ojdbc14.jar

import java.sql.*;
class OracleCon{
public static void main(String args[]){
try{
Class.forName("oracle.jdbc.driver.OracleDriver");

Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:@localhost:1521:xe","system","system");

Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("select * from Salary");
while(rs.next())
System.out.println(rs.getInt(1)+"  "+rs.getInt(2));

con.close();

}catch(Exception e){ System.out.println(e);}

}
}
  • MySql

Note : You need this Jar File to Run MySql Connection :

download the jar file mysql-connector.jar
http://www.javatpoint.com/src/jdbc/mysql-connector.jar

import java.sql.*;

class MysqlCon{
public static void main(String args[]){
try{
Class.forName("com.mysql.jdbc.Driver");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
//here test is the database name, root is the username and root is the password
Statement stmt=con.createStatement();

ResultSet rs=stmt.executeQuery("select * from salary");

while(rs.next())
System.out.println(rs.getInt(1)+"  "+rs.getString(2)+"  "+rs.getString(3));

con.close();

}catch(Exception e){ System.out.println(e);}

}
}
  • MS Access DB 

Note : You need this Jar File to Run  Connection :

download the jar file 

Link http://ucanaccess.sourceforge.net/site.html

import java.sql.*;
class Test{
public static void main(String ar[]){
 try{
   String database="student.mdb";//Here database exists in the current directory

   String url= "jdbc:ucanaccess://student.mdb";

   Connection c=DriverManager.getConnection(url);
   Statement st=c.createStatement();
   ResultSet rs=st.executeQuery("select * from login");

   while(rs.next()){
    System.out.println(rs.getString(1));
   }

}catch(Exception ee){System.out.println(ee);}

}}

MS Access Video :

Download Full Source Code

Download-icon

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s