• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to this Java and trying to write following program

import java.sql.*;
public class JDBCDemo
{
public static void main(String args[])
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc: odbc:StudTableDSN");
Statement stmt=conn.createStatement();
String query="select * from StudTable where rollno=2";
ResultSet rs=stmt.executeQuery(query);
rs.next();
System.out.println("Roll No:"+rs.getInt(1));
System.out.println("Name:"+rs.getString(2));
System.out.println("Average:"+rs.getDouble(3));
conn.close();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException se)
{
se.printStackTrace();
}
}
}


and getting the error


C:\Program Files\Java\jdk1.6.0_23\bin>javac JDBCDemo.java

C:\Program Files\Java\jdk1.6.0_23\bin>java JDBCDemo
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at JDBCDemo.main(JDBCDemo.java:9)

C:\Program Files\Java\jdk1.6.0_23\bin>


friends please help
 
Marshal
Posts: 79469
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Don’t put your own code in the “Program Files” folder. Have a look at this post for a better suggestion.
Where have you put the .jar which contains the connectors? How are you adding it to your classpath?
 
Rakesh Khire
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you for your welcome Campbell Ritchie, I done as you suggested that i moved my code but still the same problem is there.


F:\Ad_Java\Exp10>javac JDBCDemo.java

F:\Ad_Java\Exp10>java JDBCDemo
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not fou
nd and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3073)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:3
23)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at JDBCDemo.main(JDBCDemo.java:9)

F:\Ad_Java\Exp10>





and can you please help me little more and tell me that where can i find .jar??

 
Campbell Ritchie
Marshal
Posts: 79469
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So where did you put the .jar? You will have to search for the location of the ODBC driver. Try Googling, and you will find lots of places. This page, which doesn’t seem to work for Java6 and Java7, has a link to a database of drivers. I might be wrong about the numbering; those numbers might refer to EE numbers rather than SE and EE5 may be the most recent.

Go through the database; if for example you go to M for MS SQL Server, you can find about 50 different drivers in the database. Decide which is most suitable and download it. See whether this Java tutorials page helps you get a connection.
 
Campbell Ritchie
Marshal
Posts: 79469
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you look here, it would appear the most recent version of JavaEE is 6.
reply
    Bookmark Topic Watch Topic
  • New Topic