Saturday, June 21, 2008

Using Microsoft Access or Excel as the datapool

Normally we use to import a .csv file to use as datapool in the RFT.But as this tool uses all the features available in java so we can use also use Microsoft Access or Microsoft EXcel as the database.For doing this we just need to make a JDBC ODBC connection.
We can do all this in following way.
1)First go to control panel->Administrative Tools->Data Sources(ODBC)
2)Then in the User Dsn tab click add button and add a driver for access or excel and name it MyDsn.
3)select the path where you have put your .mdb or .xls file
After that we just need to use this program to connect to datasource .
Java Program for connection to the Microsoft Access database.
import java.sql.*;
public class TestConnection {
public static void main(String[] args) {
Connection con=null;
try {
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT * FROM EMPLOYEE");
// for inserting rows
// int count =stmt.executeUpdate("insert into EMPLOYEE(FIRST_NAME,LAST_NAME) values('Rahul','PERERA')");
int EMP_ID=rs.getInt(1);
String FIRST_NAME=rs.getString(2);
String LAST_NAME= rs.getString(3);
catch (Exception e){}
catch(SQLException e){}