File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

from servlet i want to use Ms Access

 
sahitya lakshmi
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sun JDBC tutorial is your best bet.
Sun JDBC Tutorial
 
Ishrayansh Nath
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}

}
}
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic