1.11M Members

DataBase connection in Jsp to MS-Access

 
0
 

hello
i am nireekshan i have some prouble in database connection
send my erres pless see and send Some Code .
//...............................//

import java.sql.*;
class Student
{
public static void main(String args[]) throws Exception
{
try
{

import java.sql.*;
class Student
{
public static void main(String args[]) throws Exception
{
try
{
String database="c:\\student.mdb";
String url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=false";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:student");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select *from studtable");
while(rs.next())
{
	int no=rs.getInt(1);
	String name=rs.getString(2);
	String address=rs.getString(3);
	System.out.println(no+" "+name+" "+address);
}
System.out.println("connected");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
***************************************************************************************************************//in the above program was working Good  ,not any arrer But Bellow Program was some arrer
##########################################################################
//
String database="c:\\student.mdb";
String url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=false";

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url);
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select *from studtable");
while(rs.next())
{
	int no=rs.getInt(1);
	String name=rs.getString(2);
	String address=rs.getString(3);
	System.out.println(no+" "+name+" "+address);
}
System.out.println("connected");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

Exception in thread "main" java.sql.SQLException:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

 
0
 

Try this code ....
I have change table name and database name....so plz update is accodingly

your problem was in red line...check it

import java.sql.*;
class student
{
public static void main(String args[]) throws Exception
   {
	try
	{
		String database="c:\\student.mdb";
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=true"; 
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		Connection con=DriverManager.getConnection(url,"","");
		Statement stmt=con.createStatement();
		ResultSet rs=stmt.executeQuery("select *from studenttable");
		while(rs.next())
			{
				int no=rs.getInt(1);
				String name=rs.getString(2);
				String address=rs.getString(3);
				System.out.println(no+" "+name+" "+address);
			}
			System.out.println("connected");				
		}
		catch(Exception e)
		{
				e.printStackTrace();
		}
	}
}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article