DataBase connection in Jsp to MS-Access

Reply

Join Date: Mar 2008
Posts: 9
Reputation: nireekshan is an unknown quantity at this point 
Solved Threads: 0
nireekshan nireekshan is offline Offline
Newbie Poster

DataBase connection in Jsp to MS-Access

 
0
  #1
Mar 25th, 2008
hello
i am nireekshan i have some prouble in database connection
send my erres pless see and send Some Code .
//...............................//
  1. import java.sql.*;
  2. class Student
  3. {
  4. public static void main(String args[]) throws Exception
  5. {
  6. try
  7. {
  8.  
  9. import java.sql.*;
  10. class Student
  11. {
  12. public static void main(String args[]) throws Exception
  13. {
  14. try
  15. {
  16. String database="c:\\student.mdb";
  17. String url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=false";
  18.  
  19. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  20. Connection con=DriverManager.getConnection("jdbc:odbc:student");
  21. Statement stmt=con.createStatement();
  22. ResultSet rs=stmt.executeQuery("select *from studtable");
  23. while(rs.next())
  24. {
  25. int no=rs.getInt(1);
  26. String name=rs.getString(2);
  27. String address=rs.getString(3);
  28. System.out.println(no+" "+name+" "+address);
  29. }
  30. System.out.println("connected");
  31. }
  32. catch(Exception e)
  33. {
  34. e.printStackTrace();
  35. }
  36. }
  37. }
  38. ***************************************************************************************************************//in the above program was working Good ,not any arrer But Bellow Program was some arrer
  39. ##########################################################################
  40. //
  41. String database="c:\\student.mdb";
  42. String url="jdbc:odbc:Driver={Microsoft Access Driver(*.mdb)};DBQ=" + database + ";DriverID=22;READONLY=false";
  43.  
  44. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  45. Connection con=DriverManager.getConnection(url);
  46. Statement stmt=con.createStatement();
  47. ResultSet rs=stmt.executeQuery("select *from studtable");
  48. while(rs.next())
  49. {
  50. int no=rs.getInt(1);
  51. String name=rs.getString(2);
  52. String address=rs.getString(3);
  53. System.out.println(no+" "+name+" "+address);
  54. }
  55. System.out.println("connected");
  56. }
  57. catch(Exception e)
  58. {
  59. e.printStackTrace();
  60. }
  61. }
  62. }
Exception in thread "main" java.sql.SQLException:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
Last edited by peter_budo; Mar 26th, 2008 at 5:18 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: p4u9999 is an unknown quantity at this point 
Solved Threads: 0
p4u9999 p4u9999 is offline Offline
Newbie Poster

Re: DataBase connection in Jsp to MS-Access

 
0
  #2
Mar 25th, 2008
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();
		}
	}
}
Last edited by peter_budo; Mar 26th, 2008 at 5:21 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC