cancel
Showing results for 
Search instead for 
Did you mean: 

Using MS Access as backend in Webdynpro Application

Former Member
0 Kudos

hi guys,

I am creating a application in webdynpro in which i want to use MS Access as Backend, so can u please tell how to use MS Access as backend.

What all needs to be done and where the database file needs to be stored etc. please give me all the details...

thanks in advance

Gaurav Makin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Gaurav,

It is pretty easy to use the MSAccess as a back end from the webdynpro applications. Take the driver as a JDBC-ODBBC driver and creat the alias name for the database server to use as a data source.Select the model as a Beanmodel while creating a model in the Webdynpro explorer.

please find the below code which will help you lot.

Please let me know if you need any further information.

package com.accenture.radar.project;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import javax.naming.InitialContext;

import javax.sql.DataSource;

/**

  • @author suvarna.chittoor

*

  • To change the template for this generated type comment go to

  • Window>Preferences>Java>Code Generation>Code and Comments

*/

public class ProjectBean {

private String name;

private String description;

private String du;

private String saveOrUpdate;

static DataSource dataSource;

private Connection connection;

private ResultSet rs;

private ArrayList duArrayList =new ArrayList();

private ArrayList projectArrayList =new ArrayList();

public ProjectBean()

{

try

{

//code to look up the datasource

InitialContext initialContext = new InitialContext();

dataSource = (DataSource)initialContext.lookup("jdbc/aliasforradar");

}

catch(Exception e)

{

System.err.print("Error Message"+e.getMessage());

}

}

public static Connection getConnection() throws SQLException, ClassNotFoundException

{

System.err.println("In Get Connection");

java.sql.Connection connection = null ;

try

{

connection = dataSource.getConnection();

}

catch (SQLException e)

{

System.err.println(e.getMessage());

throw e;

}

System.err.println("After getting Connection from the datasource");

return connection;

}

public void getDUInformation()throws SQLException, ClassNotFoundException

{

connection = getConnection();

PreparedStatement ps= connection.prepareStatement("select distinct name from du");

rs=ps.executeQuery();

while(rs.next())

{

duArrayList.add(rs.getString("name"));

}

ps.close();

connection.close();

}

public void saveProjectDetails() throws SQLException, ClassNotFoundException

{

Connection connection = null;

if(saveOrUpdate.equalsIgnoreCase("Save"))

{

connection = getConnection();

PreparedStatement ps =

connection.prepareStatement(

"insert into project values(?,?,?)");

ps.setString(1, getName());

ps.setString(2, getDescription());

ps.setString(3, getDu());

ps.executeUpdate();

connection.close();

ps.close();

}

else

{

connection = getConnection();

PreparedStatement ps =connection.prepareStatement("update project set du=?,description=? where name='"name.trim()"'");

ps.setString(1,du);

ps.setString(2,description);

ps.executeUpdate();

connection.close();

ps.close();

}

}

public void getProjectDetails() throws SQLException, ClassNotFoundException

{

Connection connection = null;

connection = getConnection();

PreparedStatement ps=connection.prepareStatement("select name,description,du from project");

rs=ps.executeQuery();

while(rs.next())

{

Project_HelperClass proj= new Project_HelperClass();

proj.setName(rs.getString("name"));

proj.setDescription(rs.getString("Description"));

proj.setDu(rs.getString("du"));

projectArrayList.add(proj);

}

ps.close();

connection.close();

}

public void getProjectInformation()

throws SQLException, ClassNotFoundException {

Connection connection = null;

connection = getConnection();

PreparedStatement ps =

connection.prepareStatement("select description,du from project where name='"name"'");

rs = ps.executeQuery();

while(rs.next())

{

this.description=rs.getString("description");

this.du=rs.getString("du");

}

connection.close();

ps.close();

}

/**

  • @return

*/

public String getDescription() {

return description;

}

public void deleteProject() throws SQLException, ClassNotFoundException

{

Connection connection = null;

connection = getConnection();

PreparedStatement ps=connection.prepareStatement("delete from sme_support where project = '"name"'");

ps.executeUpdate();

PreparedStatement ps1=connection.prepareStatement("delete from wbse where project = '"name"'");

ps1.executeUpdate();

PreparedStatement ps2=connection.prepareStatement("delete from supervisor where project = '"name"'");

ps2.executeUpdate();

PreparedStatement ps3=connection.prepareStatement("delete from du_lead where project = '"name"'");

ps3.executeUpdate();

PreparedStatement ps4=connection.prepareStatement("delete from project where name = '"name"'");

ps4.executeUpdate();

connection.close();

ps.close();

ps1.close();

ps2.close();

ps3.close();

ps4.close();

}

/**

  • @return

*/

public String getDu() {

return du;

}

/**

  • @return

*/

public ArrayList getDuArrayList() {

return duArrayList;

}

/**

  • @return

*/

public String getName() {

return name;

}

/**

  • @param string

*/

public void setDescription(String string) {

description = string;

}

/**

  • @param string

*/

public void setDu(String string) {

du = string;

}

/**

  • @param list

*/

public void setDuArrayList(ArrayList list) {

duArrayList = list;

}

/**

  • @param string

*/

public void setName(String string) {

name = string;

}

/**

  • @return

*/

public ArrayList getProjectArrayList() {

return projectArrayList;

}

/**

  • @param list

*/

public void setProjectArrayList(ArrayList list) {

projectArrayList = list;

}

/**

  • @return

*/

public String getSaveOrUpdate() {

return saveOrUpdate;

}

/**

  • @param string

*/

public void setSaveOrUpdate(String string) {

saveOrUpdate = string;

}

}

Thanks and regards

Ratnakar reddy alwala

Former Member
0 Kudos

hi Ratnakar,

thanks for the code it will help a lot

but please tell me how to create alias name for the database

and also while selecting beanmodel it is asking to import javabean

so which javabean to import and how to create bean

thanks & regards...

Gaurav

Answers (1)

Answers (1)

former_member182294
Active Contributor
0 Kudos

Hi Gaurav,

You should use JDBC ODBC driver. You can refer the following links to connect to MS Access db.

<a href="http://www.javaworld.com/javaworld/javaqa/2000-09/03-qa-0922-access.html">http://www.javaworld.com/javaworld/javaqa/2000-09/03-qa-0922-access.html</a>

<a href="http://developers.sun.com/product/jdbc/drivers">http://developers.sun.com/product/jdbc/drivers</a>

<a href="http://msdn2.microsoft.com/en-us/data/aa937724.aspx">http://msdn2.microsoft.com/en-us/data/aa937724.aspx</a>

In this case you can use Java Bean model where Java Bean contains the logic to connect to MS Access and retrieves the data.

Regards

Abhilash