Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]

843859Sep 13 2006 — edited Sep 19 2006
Hi friends,
Im using Apache Tomcat Server 5.5 and MS Access as my Data Base, but now im facing problem in accessing data from the database through servlet.
and im getting this ERROR : " java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Disk or network error."
What im trying to do is, Taking login name and password from a JSP, sending data to servlet to check whether its present in database, if present then authenticate or else throw an error....
My code looks as:-

Login.jsp:-
------------------------------------------------------------------------------------------------------------------------------------------------------------
<HTML>
<HEAD>
<TITLE> Login Form </TITLE>
</HEAD>
<BODY bgcolor="#666666" LINK="#3300FF" VLINK="#3300FF">
<BR><BR><HR>
<MARQUEE> Welcome to Login Form </MARQUEE>
<HR>
<BR>

<FORM NAME='Login'ACTION='DataBaseCheck' METHOD=POST>
<BR><BR><BR><BR>
<CENTER>
<table border="1" width="350">
<caption> Login Screen </caption>
<colgroup span="2">
<col width="30"></col>
<col width="70"></col>
</colgroup>
<tr>
<td>
<BR><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : &nbsp;&nbsp;<input type="text" name="name" size="20">
<BR><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Password &nbsp;&nbsp; :&nbsp;&nbsp;&nbsp;<input type="password" name="pass" size="20">
<BR><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="submit" Value="submit">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="reset" Value="Reset">
<BR><BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Register <A>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>

</table>
</CENTER>
</FORM>
</BODY>
</HTML>
----------------------------------------------------------------------------------------------------------------------------------------------------------------


DataBaseCheck.java:-
------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;


public class DataBaseCheck extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
//pass the ServletConfig object to super class
super.init(config);
}

//process the HTTP GET request
public void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{
doPost(request,response);
}

//process the HTTP POST request
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException
{

String form_name = request.getParameter("name");
String form_password = request.getParameter("pass");

String errormsg = "";
boolean errorDetected = false;
boolean auth = false;

String[] database_row = new String[10];

Connection connection;
Statement statement;

try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println(" Driver detected");

connection=DriverManager.getConnection("jdbc:odbc:TempDatabase");
System.out.println(" Connection established");

statement = connection.createStatement();
System.out.println(" Statement Created");

String selectQuery = "SELECT * FROM profile where First_Name=\'" form_name"\' and Password=\'"+form_password+"\'";
boolean resultSet = statement.execute(selectQuery);
if(resultSet)
{
ResultSet set = statement.getResultSet(); //Fetch the entire row and store it in a string array....
if(set!=null)
{
ResultSetMetaData metaData = set.getMetaData();
int columns=metaData.getColumnCount();
database_row = new String[columns];

for (int i=0;i<columns ;i++ )
{
database_row="";
}

auth= set.next();
}

if( auth== true)
{
// give the authentication to user....
HttpSession sess=request.getSession();
sess.setAttribute("user",database_row[1]);
response.sendRedirect("Access.jsp");
}

}
else
{
//user id is not present in the database, has to signup
connection.close();
response.sendRedirect("NonUser.jsp");
}

} //try close

catch(Exception e)
{
e.printStackTrace();
}

}
}


Help me in solving this problem.......

Thanks in advance....
Nandish
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2006
Added on Sep 13 2006
3 comments
350 views