Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java/JDBC Help

  Asked By: Ayden    Date: Apr 29    Category: Java    Views: 835
  

I need help for Java/JDBC. I hava created a database. I have set the
odbc driver (viz. addr_book). Then I wrote the following java
program. Tried to compile it. It gave the error :

C:\ABC\Java\JDBC>java MakingAStatement.java
Exception in thread "main" java.lang.NoClassDefFoundError:
MakingAStatement/java
---------------------------------------------------
import java.lang.*;
import java.sql.*;

public class MakingAStatement
{
public static void main (string[] args)
{
// Load the driver
try
{
// Load the driver class
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

// This defines the data source for the driver
String sourceURL = new String("jdbc:odbc:addr_book");

// Create connection through the DriverManager
Connection databaseConnection = DriverManager.getConnection
(sourceURL);

Statement statement = databaseConnection.createStatement();

ResultSet authorNames = statement.executeQuery("SELECT lname,
fname FROM Address_Book");

// Output the resultset data
while(authorNames.next())
System.out.println(authorNames.getString("lname") + ", " +
authorNames.getString("fname"));
}
catch(ClassNotFoundException cnfe)
{
System.err.println(cnfe);
}
catch(SQLException sqle)
{
System.err.println(sqle);
}
}
}



Share: 

 

2 Answers Found

 
Answer #1    Answered By: Danny Perkins     Answered On: Apr 29

Change the string  to String in the statement

public static  void main  (string[] args)

it will work, Its is compiling here

 
Answer #2    Answered By: Riley-jack Johnson     Answered On: Apr 29

You are using the wrong command to compile:
java MakingAStatement.java
should be
javac MakingAStatement.java


To run the compiled program after fixing your errors,
java MakingAStatement

 
Didn't find what you were looking for? Find more on Java/JDBC Help Or get search suggestion and latest updates.




Tagged: