Hi, Folks, I started to learn how to use
JDBC recently. Now I got a difficulty to connect
my Access database. I have Access in my computer which runs NT. I know I need to use
JDBC.ODBC to get connection in the following coding. But when I execute the class, I get
an exception:
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found
and no default driver specified. What should I do? Is the classpath or the ODBC Data Source Manager in the Control Panel?
And how to do it?
Thank you very much. I really appreciate your help.
Frank
import java.sql.*;
public class Example1 {
��
public static void main (
String args[]) {
����
try {
������
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
����
}
����
catch (Exception e) {
������
System.out.println("JDBC-ODBC driver failed to load.");
������
return;
����
}
����
try {
������
Connection conn = DriverManager.getConnection("jdbc:odbc:inventory","","");
������
Statement stmt = conn.createStatement();
������
ResultSet rs = stmt.executeQuery("SELECT * FROM inventory ORDER BY price");
������
ResultSetMetaData rsmd = rs.getMetaData();
������
int numberOfColumns = rsmd.getColumnCount();
������
int rowCount = 1;
������
while (rs.next()) {
��������
for (int i=1; i<=numberOfColumns; i++) {
����������
System.out.println(rs.getString(i) + " ");
��������
}
��������
System.out.println("");
��������
rowCount++;
������
}
������
stmt.close();
����
}
����
catch (Exception e) {
������
System.out.println(e);
����
}
��
}
}
[This message has been edited by Thomas Paul (edited January 04, 2001).]