[RESOLVED] trying to get jdbc program to work
hey i tried to run this java code after compiling it
Code:
// JDBC|Test – complete code
public class JDBCTest {
public static void main(String args[]){
RunDB runDB = new RunDB();
try{
runDB.loadDriver();
runDB.makeConnection();
runDB.buildStatement();
runDB.executeQuery();
}catch(Exception e){
e.printStackTrace();
}
}
}
&
Code:
//RunDB
import java.sql.*;
public class RunDB {
Connection connection;
Statement statement;
public void loadDriver() throws ClassNotFoundException{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
public void makeConnection() throws SQLException {
connection=
DriverManager.getConnection("jdbc:odbc:purchaseOrder");
}
public void buildStatement() throws SQLException {
statement = connection.createStatement();
}
public void executeQuery() throws SQLException {
boolean foundResults =
statement.execute("SELECT * FROM Transaction");
if(foundResults){
ResultSet set = statement.getResultSet();
if(set!=null) displayResults(set);
}else {
connection.close();
}
}
void displayResults(ResultSet rs) throws SQLException {
ResultSetMetaData metaData = rs.getMetaData();
int columns=metaData.getColumnCount();
String text="";
while(rs.next()){
for(int i=1;i<=columns;++i) {
text+="<"+metaData.getColumnName(i)+">";
text+=rs.getString(i);
text+="</"+metaData.getColumnName(i)+">";
text+="n";
}
text+="n";
}
System.out.println(text);
}
}
and when i tried to rn the code i get the following errors
E:\Work\programming\java\JavaPrograms>java rundb
Exception in thread "main" java.lang.NoClassDefFoundError: rundb (wrong name: Ru
nDB)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
E:\Work\programming\java\JavaPrograms>
what have i done wrong
(i got the code of the following site
http://www.developer.com/design/arti...0925_3571661_3
i have got the code in this folder
E:\Work\programming\java\JavaPrograms
and the database in this folder
E:\Work\programming\java\database
Re: trying to get jdbc program to work
java RunDB
not
java rundb
Case is important for Java class names, even on the command line.
And you want
java JDBCTest
anyway, because that class contains the main() method.
Re: trying to get jdbc program to work
thanks for the reply, so rundb (wrong name: RunDB) is basically dumbo use RunDB not rundb
i did java JDBCTest and got the following error message, i have added a purchaseOrder.mdb to the ODBC Data Source Administrator,
E:\Work\programming\java\JavaPrograms>java JDBCTest
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 RunDB.makeConnection(rundb.java:14)
at JDBCTest.main(jdbctest.java:10)
E:\Work\programming\java\JavaPrograms>
i checked in the System DSN, and the database file does seem to have been added
what am i doing wrong?
Re: trying to get jdbc program to work
Sorry, I don't use ODBC, so I can't help you there.
Re: trying to get jdbc program to work
thanks for the help anyway
you think anyone on this forum might be able to help me
Re: trying to get jdbc program to work
hey i finally got it to work, i needed to add the file to user DSN database, adding it to the System DSN or the File DSN did not work, interestingly eough the article stated that i needed to add it to the File DSN