File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes from servlet i want to use Ms Access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "from servlet i want to use Ms Access" Watch "from servlet i want to use Ms Access" New topic
Author

from servlet i want to use Ms Access

sahitya lakshmi
Greenhorn

Joined: Feb 21, 2006
Posts: 4
hi,
to servlet i want to retrieve data from msaccess.i am getting how to get the data source name and i am not having anyidea about ms access.please give me the detail code to do this.this is my code and i want to know how to get datasource name and the connection of jdbc odbc

import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpSession ;

public class Check extends HttpServlet

{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
String userName= request.getParameter("fname");
String user_id = "";
String user_password = request.getParameter("epassword");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Online Questionnaire-Login Form</title>");
out.println("</head>");
out.println("<body>");
String dataSourceName = "db1.mdb";
String dbURL = "jdbc dbc:" + dataSourceName;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(dbURL, "","");
Statement s = con.createStatement();
s.execute("select id,name from login");
ResultSet rs = s.getResultSet();
if (rs != null)
while ( rs.next() )
{
System.out.println("Data from login: " + rs.getString(1) );
}
s.close();
con.close();
}
catch(Exception e)
{
System.out.println(e);
}

}
}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"PQR"
It appears you have changed your display name to something that is no longer valid. Accounts with invalid display names get deleted, and are less likely to get help.

Please change it back immediately.

Dave
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Sun JDBC tutorial is your best bet.
Sun JDBC Tutorial
Ishrayansh Nath
Ranch Hand

Joined: Nov 05, 2004
Posts: 45
Hi,
In Ms-Access
First Step

you create Database name like Db1.after u click Create Table Design
get field entry ..
u can create column ..if you save ,it will ask table.
u save table name.
after u can enter the rows for particular column.

Second Step.

Go to control panel
Go to Datasource(ODBC)

Create User DSN -->click add button-->select MS-Access driver.
Enter DAta Source Name
Enter Database Name
Click select button ---> select your drive and select ur Database(mdb file).

that DataSource Name You can give ur code....


import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpSession ;

public class Check extends HttpServlet

{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{
String userName= request.getParameter("fname");
String user_id = "";
String user_password = request.getParameter("epassword");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Online Questionnaire-Login Form</title>");
out.println("</head>");
out.println("<body>");
String dataSourceName = "db1.mdb";
String dbURL = "jdbc dbc:" + dataSourceName;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(jdbc dbc b1, "","");
Statement s = con.createStatement();
ResultSet rs = stmt.executeQuery( "select id,name from login") ;
while(rs.next())
{
System.out.println("id from login: " + rs.getString(0) );
System.out.println("Name from login: " + rs.getString(1) );

}
s.close() ;
stmt.close() ;
conn.close() ;
}
catch(Exception e)
{
System.out.println(e);
}

}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: from servlet i want to use Ms Access