Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

error when i run the program

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the program and I am trying to connect to MS Access database.



import java.sql.*;

class jdbcDemo
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:Part6";
Connection con=DriverManager.getConnection(url);
Statement stmt;
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SELECT Auth_ID, Auth_Name FROM AUTHOR_t");

while(rs.next())
{
int i=rs.getInt(1);
String name=rs.getString(2);
System.out.println("Name="+name);

}

stmt.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}

}



The Exception I am getting when I am running the program is

java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at jdbcDemo.main(jdbcDemo.java:13)
[ August 09, 2006: Message edited by: sai donthneni ]
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check whether your DataSourceName is pointing to your database correctly or not.If not configure that correctly.

and use finally block to close your connection and statement.
 
sai donthneni
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My datasource has been mentioned properly. Do I have to mention that it is on the localhost? My database name is Part6. Do I have to download the drivers seperately or do they come with the database server itself?
 
Get me the mayor's office! I need to tell her about this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic