Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 10:24 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: servlet coding
PostPosted: Fri Apr 08, 2011 4:08 am 
Offline
Newbie
User avatar

Joined: Thu Apr 07, 2011 8:57 am
Posts: 5
Has thanked: 0 time
Have thanks: 0 time

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


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: servlet coding
PostPosted: Fri Apr 08, 2011 1:51 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 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;
    }


}
 

_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 Connect to database Microsoft access within jsp servlet
 How can i redirect to a one servlet from a two jsp page?
 data leakage detection coding in java
 coding a simple packet sniffer
 I download the phone book coding from your site
 search for coding java/jsp for translation text
 Servlet & JSP
 Download a PDF file using JSP or servlet
 jsp and servlet
 How to write a PHP coding to list out all files and director

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team