Total members 11893 |It is currently Sat Nov 09, 2024 5:56 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Can you please send us a sample java servlet project using MS Access
database and Context.xml and web.xml file code for MS Access database.




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

web.xml is use for navigation configuration something like this :
Code:


<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
     version="2.4">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
    <welcome-file>
            index.jsp
        </welcome-file>
    </welcome-file-list>
</web-app>



here is example but for mysql ( reading subtitles of films).
Code:


 
import java
.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.http.HttpServletResponse;
 
public class allsubtitles 
{
        private final int limit=25;
    /** Creates a new instance of allsubtitles */
      public String DoFilmSearch(String page,String letter) throws IOException
    
{
         
      String returnTable 
= "";
       if(letter==null)letter="A";
            
      
      
     if
(page==null)page="1";
      int mypage=Integer.parseInt(page);
      int myBase=(limit*mypage)-limit;
      int myLimit=(limit*mypage);        
        boolean flag
=false;
         try{
            try {
                Class.forName("org.gjt.mm.mysql.Driver");
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
         Connection connection =
                    DriverManager.getConnection("jdbc:mysql://localhost/mysite?user=root&password=root");
                          String sql=null;
                    Statement statement = connection.createStatement();
                    if(letter.equals("0-9"))
                      sql="Select Films.FILM_ID,FILM_NAME As 'Film name' ,COUNT(TRGMA_ID)As 'Subtitles' ,FILM_YEAR" +
                            "  from Films Left join Trgma on(Films.FILM_ID=Trgma.FILM_ID) where FILM_NAME like('0%') OR " +
                              "FILM_NAME like('1%')  OR FILM_NAME like('2%')  OR FILM_NAME like('3%')  OR FILM_NAME like('4%')  OR FILM_NAME like('5%')  OR " +
                              "FILM_NAME like('6%')  OR FILM_NAME like('7%')  OR FILM_NAME like('8%')  OR FILM_NAME like('9%')  " +
                            " group by FILM_NAME,FILM_YEAR order by 'Film name' ,Subtitles limit "+myBase+","+myLimit+ ";";
                    else
                          sql
="Select Films.FILM_ID,FILM_NAME As 'Film name' ,COUNT(TRGMA_ID)As 'Subtitles' ,FILM_YEAR" +
                            "  from Films Left join Trgma on(Films.FILM_ID=Trgma.FILM_ID) where FILM_NAME like('"+letter+"%')" +
                            " group by FILM_NAME,FILM_YEAR order by 'Film name' ,Subtitles limit "+myBase+","+myLimit+ ";";
                    ResultSet myresult= (ResultSet) statement.executeQuery(sql);
                 
                    ResultSetMetaData myMetaData 
=(ResultSetMetaData) myresult.getMetaData();
                    int size=myMetaData.getColumnCount();   

                     
                    returnTable
= "<table   >";
                   returnTable+="<tr >";
                    for(int i=2;i<=size-1;i++)
                    {
                    returnTable+="<th>"+myMetaData.getColumnName(i)+"</th>";   
                    
}
                    returnTable+="</tr>";
                    
                while
(myresult.next())
                {
                   returnTable+="<tr>";
                     
                     flag
=true;
                       returnTable+="<td><a href=FilmTrgma.jsp?FILM_ID="+myresult.getString(1)+">"+myresult.getString(2)+"("+myresult.getString(4)+")"+"</a></td>";
                       returnTable+="<td>"+myresult.getString(3)+"</td>";
                     
                
                   returnTable
+="</tr>";
                }
                   if(!flag)
                       returnTable+="<tr><td colspan=2> No results found </td></tr>";
                   
                      if
(letter.equals("0-9"))
                      sql="Select  COUNT(FILM_ID)  " +
                            "  from Films  where FILM_NAME like('0%') OR " +
                              "FILM_NAME like('1%')  OR FILM_NAME like('2%')  OR FILM_NAME like('3%')  OR FILM_NAME like('4%')  OR FILM_NAME like('5%')  OR " +
                              "FILM_NAME like('6%')  OR FILM_NAME like('7%')  OR FILM_NAME like('8%')  OR FILM_NAME like('9%')  " +
                            " ;";
                      else 
                        sql
="Select COUNT(FILM_ID) from Films  where FILM_NAME like('"+letter+"%')";
                        myresult= (ResultSet) statement.executeQuery(sql);
                        myresult.next();
                         returnTable+="<tr><td colspan=2>Page: "; 
                        int count
=myresult.getInt(1);
                        int i=0;
                        while(count>0)
                        {
                            i++;
                            if(i!=Integer.parseInt(page))
                            returnTable+="<a href=FilmSearchResult.jsp?page="+i+"&&letter="+letter+">"+i+"</a>|";
                                       else 
                            returnTable
+="<u>"+i+"</u>|"; 
                            count
-=limit;
                        }
                   returnTable+="</td></tr></table> ";         
                   connection
.close();
                   statement.close();
         
              
} 
        
       catch 
(SQLException ex) {
            ex.printStackTrace();
        }
  
     return returnTable
;
 
            
    
}
    
}

 


Check these topics :
java/servlet-connectivity-with-ms-access-t7406.html
servlets-jsp/servlet-coding-t7380.html

_________________
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 : sample project
 Can anybody give me a sample project report on mathematics f     -  
 Help in C# sample, SDP in VoIP SIP calls     -  
 Help for my project     -  
 can u help me with my project plz     -  
 java project     -  
 Help in My Java Project !!!!     -  
 Project Post Example     -  
 Suggestion for my project     -  
 Java Project     -  
 Servlet Help for my project!!     -  



cron





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