0

I've installed MaxDB in my local machine and I'm trying to make a connection to it using Java.

And I'm getting this error when running :

Exception in thread "main" java.lang.ClassNotFoundException: com.sap.dbtech.jdbc.DriverSapDB

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)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at sap.maxdb.Hello.main(Hello.java:15)

This is the code I'm using :

package sap.maxdb;

import java.sql.*;

public class Hello
{
public static void main(String[] args) throws ClassNotFoundException, SQLException
{
String username = "DBM";
String password = "azerty";
String dbname = "SAPDB";

Class.forName ("com.sap.dbtech.jdbc.DriverSapDB");
String url = "jdbc:sapdb://" + dbname;

Connection connection = DriverManager.getConnection (url, username, password);
Statement stmt = connection.createStatement ();
ResultSet resultSet = stmt.executeQuery ("SELECT * FROM HOTEL.CUSTOMER");
resultSet.next ();
String hello = resultSet.getString (1);
System.out.println (hello);

resultSet.close ();
stmt.close();
connection.close ();
}
}

I did like they said in their website :

set CLASSPATH=%CLASSPATH%;C:\Program Files\sdb\programs\runtime\jar\sapdbc.jar

But I get always the same error.

I know that I'm missing something but can't find it °!°

Waiting for your help.

Thanks.

5
  • can you post the full stacktrace? Commented Jun 28, 2011 at 15:18
  • 4
    try set CLASSPATH="%CLASSPATH%;C:\Program Files\sdb\programs\runtime\jar\sapdbc.jar" Commented Jun 28, 2011 at 15:25
  • You must quote your classpath if it contains a space. Commented Jun 28, 2011 at 15:33
  • I tried with and without quotes and it's not working yet. Commented Jun 28, 2011 at 15:42
  • How are you running this? From an IDE, from the command line, from a script? A description of what you are doing, or better yet, the actual command/script you are running will help. Commented Jun 28, 2011 at 16:38

3 Answers 3

1

What does "install" mean? Basically, the db server must be installed and running.

Step two is to add the driver (which you can find under C:\Program Files\sdb\programs\runtime\jar\sapdbc.jar, assuming this applies to your installation too) to the build path of your project. If the driver class cannot be found, it'll raise a ClassNotFoundException as you experienced.

You don't mention which IDE you are using, but try to set your project buildpath from the context menu.

Sign up to request clarification or add additional context in comments.

1 Comment

Then right click on the project, Build Path -> Configure Build Path -> Libraries tab -> Add External JARs. Select the sapdbc.jar from the file browser and click OK. Build path problems should be resolved now.
1

Try adding the following code to make sure that your application picks up the CLASSPATH that you specified:

    Map<String, String> env = System.getenv();
    for (String envName : env.keySet()) {
        System.out.format("%s=%s%n", envName, env.get(envName));
    }

Comments

0

Copy the driver's jar file to the 'lib' folder of the server. Then restart the server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.