Total members 11894 |It is currently Mon Nov 25, 2024 4:13 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





plz send the complete steps for making a connection between tomcat 6.0 and Ms access. I am trying to develop a
web application.




Author:
Newbie
User avatar Posts: 5
Have thanks: 0 time

hi
First you will need to open a connection to your MS access database using the JDBC driver and you will need to add the JDBC needed jars to your tomcat web project libs .

Here a code to open a connection to msaccess db from java code :
Code:

import java
.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class 
MSAccessDAO {


    private 
String username;
    private 
String password;
    private 
String driver;
    private 
String URL =
            
"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\MSDB\\rundb.mdb;}";

    public 
MSAccessDAO(String usernameString passwordString driver) {
        
this.username username;
        
this.password password;
        if (
driver == null || driver.trim() == "") {
            
this.driver "sun.jdbc.odbc.JdbcOdbcDriver";
        }

    }

    public 
Connection getConnection() {
        try {

            Class.
forName(driver);

            
Connection connection DriverManager.getConnection(URLusernamepassword);
            return 
connection;
        } catch (
SQLException e) {
            
e.printStackTrace();
        } catch (
ClassNotFoundException ex) {
            
ex.printStackTrace();
        }
        return 
null;

    }

    public static 
void main(String[] argsthrows Exception {
        
Connection connection null;
        try {
               
MSAccessDAO accessConnect = new MSAccessDAO("admin","admin"null);
               
connection =accessConnect.getConnection();
               if(
connection!=null){
                   
// Do your work .
               
}else {
                   
System.out.println("Failed to create connection to DB");
               }


        }
finally {
            
connection.close();
        }
    }

    public 
String getURL() {
        return 
URL;
    }

    public 
void setURL(String URL) {
        
this.URL URL;
    }

    public 
String getDriver() {
        return 
driver;
    }

    public 
void setDriver(String driver) {
        
this.driver driver;
    }

    public 
String getPassword() {
        return 
password;
    }

    public 
void setPassword(String password) {
        
this.password password;
    }

    public 
String getUsername() {
        return 
username;
    }

    public 
void setUsername(String username) {
        
this.username username;
    }


}
 


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : servlet coding
 jsp and servlet     -  
 Servlet & JSP     -  
 how to run servlet and rmi     -  
 JSP and Servlet     -  
 I am new in PHP, want coding or PHP file     -  
 Java Coding     -  
 Servlet Help for my project!!     -  
 Java Servlet and JSP     -  
 SERVLET/JSP DOUBT     -  
 Standard Huffman Coding     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com