Jump to content
JasperReports Library 7.0 is now available ×

Recital JDBC error - No suitable driver


ktrinad

Recommended Posts

By: Rex Jun Cabanilla - rexjun

Recital JDBC error - No suitable driver

2003-04-10 06:13

Using iReport-0.0.9, Recital's JDBC Driver fails during database connection testing. The error message is..

 

ERROR

SQL problems:

No suitable driver

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(...)

...

CODE 4

 

But the same driver on iReport-0.0.5 does not fail the database connection test.

 

Do I have a non-compliant JDBC driver? Is there a difference in JDBC functionality between 0.0.9 and 0.0.5?

 

What is the best thing to do?

 

 

 

 

 

By: Giulio Toffoli - gt78

RE: Recital JDBC error - No suitable driver

2003-04-10 14:25

In effect there is an importat difference between 0.0.5 and 0.0.9: in the last version the access to database using JDBC by iReport (i.e. to test connections or retrive database fields) is performed using an external program (pure java program) called IReportJDBCConnector. This means 2 things:

1) you need to have this class in the classpath (it is shipped with iReport from 0.0.8 and is present in bin directory that it's already in the classpath)

2) you must add your driver in the Java Classpath (no MS Java classpath).

 

I hope this helps you.

 

Giulio

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 07:33

I still get the same error...

 

I'm providing the full error message including the line numbers...

 

ERROR

SQL problems:

No suitable driver

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(DriverManager.java:532)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at IReportJDBCConnector.main(IReportJDBCConnector.java:62)

CODE 4

 

The JBDC driver is already in the Java Classpath. When I remove it from the classpath, I get ClassNotFoundError.

 

I get a successful database connection using another JDBC driver like the jtopen driver for IBM AS400, so I guess there is nothing wrong with my installation.

 

Can you help me isolate the problem further?

 

By the way, this is a nice piece of work. Keep it up!!!

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 07:40

I still get the same error...

 

I'm providing the full error message including the line numbers...

 

ERROR

SQL problems:

No suitable driver

java.sql.SQLException: No suitable driver

at java.sql.DriverManager.getConnection(DriverManager.java:532)

at java.sql.DriverManager.getConnection(DriverManager.java:171)

at IReportJDBCConnector.main(IReportJDBCConnector.java:62)

CODE 4

 

The JBDC driver is already in the Java Classpath. When I remove it from the classpath, I get ClassNotFoundError.

 

I get a successful database connection using another JDBC driver like the jtopen driver for IBM AS400, so I guess there is nothing wrong with my installation.

 

Can you help me isolate the problem further?

 

By the way, this is a nice piece of work. Keep it up!!!

 

 

 

 

By: Giulio Toffoli - gt78

RE: Recital JDBC error - No suitable driver

2003-04-11 07:54

I think that the poblem is the url that you use to connect to the database (No suitable driver is throws when there is not a driver to decode the particular protocol).

 

i.e. mysql:// is a protocol

as400:// is a protocol

ecc....

 

Check your JDBC url.

 

Giulio

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 10:24

I created a java program to validate the url and driver name I was using. Portion of the code is, as follows:

 

========

 

try {

 

Class.forName ("Recital.sql.RecitalDriver").newInstance();

 

String url = "jdbc:Recital:"SERVERNAME=192.168.0.10;DIRECTORY=/usr/recital-8.4/uas/netdata/metro/data;USERNAME=root;PASSWORD=redhat73";

 

Connection con = DriverManager.getConnection(url, "uas", "uas");

 

Statement stmt = con.createStatement();

 

DatabaseMetaData dbmd = con.getMetaData();

System.out.println(dbmd.getDriverVersion() + "n" + dbmd.getDriverName());

con.close();

} catch (Exception e) {

system.out.flush();

system.err.flush();

e.printStackTrace();

}

 

=====

 

I got the following results...

 

1.0

Recital JDBC Driver

 

... without any exception being thrown.

 

Notice that the URL does not contain the any // after jdbc:Recital:. Putting the // triggers an exception, saying...

 

java.sql.SQLException: Invalid URL format for Recital. Expected SERVERNAME= not //SERVERNAM

 

Is IReportJDBCConnector reforming the url before calling DriverManager.getConnection ?

 

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 10:25

I created a java program to validate the url and driver name I was using. Portion of the code is, as follows:

 

========

 

try {

 

Class.forName ("Recital.sql.RecitalDriver").newInstance();

 

String url = "jdbc:Recital:"SERVERNAME=192.168.0.10;DIRECTORY=/usr/recital-8.4/uas/netdata/metro/data;USERNAME=root;PASSWORD=redhat73";

 

Connection con = DriverManager.getConnection(url, "uas", "uas");

 

Statement stmt = con.createStatement();

 

DatabaseMetaData dbmd = con.getMetaData();

System.out.println(dbmd.getDriverVersion() + "n" + dbmd.getDriverName());

con.close();

} catch (Exception e) {

system.out.flush();

system.err.flush();

e.printStackTrace();

}

 

=====

 

I got the following results...

 

1.0

Recital JDBC Driver

 

... without any exception being thrown.

 

Notice that the URL does not contain the any // after jdbc:Recital:. Putting the // triggers an exception, saying...

 

java.sql.SQLException: Invalid URL format for Recital. Expected SERVERNAME= not //SERVERNAM

 

Is IReportJDBCConnector reforming the url before calling DriverManager.getConnection ?

 

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 10:30

 

The correct url is ...

 

String url = "jdbc:Recital:SERVERNAME=192.168.0.10;DIRECTORY=/usr/recital-8.4/uas/netdata/metro/data;USERNAME=root;PASSWORD=redhat73";

 

... with the double-quotes removed before SERVERNAME.

 

USERNAME and PASSWORD has to be included in the url otherwise exception is thrown by Recital JDBC driver.

 

 

 

 

 

By: Giulio Toffoli - gt78

RE: Recital JDBC error - No suitable driver

2003-04-11 14:32

Hi rex,

 

Do you have succesfully solved the problem or not ?

 

Giulio

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-11 19:52

Not yet.

 

The driver name and url that I've been using is working on another java program. The values are:

 

driver name = "Recital.sql.RecitalDriver"

url = "jdbc:Recital:"SERVERNAME=192.168.0.10;DIRECTORY=/usr/recital-8.4/uas/netdata/metro/data;USERNAME=root;PASSWORD=redhat73"

 

I cannot see the source code for IReportJDBCConnector... Can you tell me if

IReportJDBCConnector is reforming the url before calling DriverManager.getConnection ?

 

Thanks for your support...

 

 

 

 

By: Giulio Toffoli - gt78

RE: Recital JDBC error - No suitable driver

2003-04-12 02:25

I have added IReportJDBCConnector.java to CVS repository.

You can download it at:

 

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ireport/iReport/IReportJDBCConnector.java

 

I post here the entire code, because it's very simple...

 

 

 

____________________

 

import java.sql.*;

 

public class IReportJDBCConnector

{

public static void main(String[] args)

{

boolean test = false;

 

String query = "";

String jdbDriver = "";

String jdbcUser ="";

String jdbcPassword ="";

String jdbcUrl ="";

String error_msg = "";

Exception exx = null;

 

System.setErr(System.out);

try

{

 

//long start = System.currentTimeMillis();

if(args.length == 0)

{

usage();

System.out.println("CODE 1");

System.exit(1);

}

 

for (int i=0; i<args.length; ++i)

{

if (args.startsWith("-jdriver"))

jdbDriver = args.substring(8);

else if (args.startsWith("-juser"))

jdbcUser = args.substring(6);

else if (args.startsWith("-jpasswd"))

jdbcPassword = args.substring(8);

else if (args.startsWith("-jurl"))

jdbcUrl = args.substring(5);

else if (args.equals("-test"))

{

test = true;

}

else if (args.equals("-query"))

{

if (i+1 < args.length) i++;

query = args.replace('"',' ');

}

else if (i+1 != args.length)

{

//System.out.println("No more params expected!");

usage();

System.out.println("CODE 2");

System.exit(1);

}

}

 

//System.out.println("Opening connection....");

//System.out.flush();

Class.forName( jdbDriver );

Connection conn = DriverManager.getConnection(jdbcUrl,

jdbcUser,

jdbcPassword);

 

Statement stmt = null;

 

 

stmt = conn.createStatement();

if (test)

{

System.out.println("SUCCESS");

System.out.println("***XXX***");

System.out.flush();

//conn.close();

System.exit(0);

}

 

if (query.length()>0)

{

//System.out.println("Executing query " + query);

//System.out.flush();

String output = "SUCCESSn";

ResultSet rs = stmt.executeQuery(query);

ResultSetMetaData rsmd = rs.getMetaData();

 

for (int i=1; i <=rsmd.getColumnCount(); ++i)

{

output += rsmd.getColumnName(i)+ "--" + getJdbcTypeClass(rsmd.getColumnType(i) ) + "n";

}

 

System.out.println(output);

System.out.flush();

conn.close();

System.exit(0);

 

}

 

}catch (NoClassDefFoundError ex)

{

error_msg = "NoClassDefFoundError!!nCheck your classpath!";

System.out.println("ERROR");

System.out.println(error_msg);

System.out.println("CODE 3");

System.out.flush();

 

System.exit(1);

}

catch (ClassNotFoundException ex)

{

error_msg = "ClassNotFoundError:n"+ ex.getMessage() +"nnCheck your classpath!";

exx = ex;

}

catch (java.sql.SQLException ex)

{

error_msg = "SQL problems:n"+ex.getMessage();

exx = ex;

}

catch (Exception ex)

{

error_msg = "General problem:n"+ex.getMessage()+"nnCheck username and password; is the DBMS active ?!";

exx = ex;

}

 

java.io.StringWriter s = new java.io.StringWriter();

exx.printStackTrace(new java.io.PrintWriter(s));

System.out.println("ERROR");

System.out.println(error_msg);

System.out.println(s);

System.out.flush();

System.out.println("CODE 4");

System.exit(1);

}

 

 

/**

*

*/

private static void usage()

{

System.out.println( "ERROR" );

System.out.println("Syntax error of the command");

System.out.println( "IReportJDBCConnector usage:" );

System.out.println( "tjava IReportJDBCConnector [options]n" );

System.out.println( "t -testtonly test the connection" );

System.out.println( "t -jdriver<jdbcdriver>tuse this JDBC driver" );

System.out.println( "t -juser<jdbc user>tdatabase user" );

System.out.println( "t -jpasswd<jdbc pass>tdatabase password" );

System.out.println( "t -jurl<jdbc url>tJDBC url" );

System.out.println( "t -query"<query>"tQuery to execute" );

}

 

 

/**

* Thanx to Jackie Manning j.m@programmer.net for this method!!

*/

public static String getJdbcTypeClass( int t ) {

String cls = "java.lang.String";

switch( t ) {

case java.sql.Types.TINYINT:

case java.sql.Types.BIT:

cls = "java.lang.Byte";

break;

case java.sql.Types.SMALLINT:

cls = "java.lang.Short";

break;

case java.sql.Types.INTEGER:

cls = "java.lang.Integer";

break;

case java.sql.Types.REAL:

case java.sql.Types.DOUBLE:

case java.sql.Types.NUMERIC:

case java.sql.Types.DECIMAL:

cls = "java.lang.Double";

break;

case java.sql.Types.CHAR:

case java.sql.Types.VARCHAR:

cls = "java.lang.String";

break;

 

case java.sql.Types.BIGINT:

cls = "java.lang.Long";

break;

case java.sql.Types.DATE:

case java.sql.Types.TIME:

cls = "java.util.Date";

break;

case java.sql.Types.TIMESTAMP:

cls = "java.sql.Timestamp";

break;

}

return cls;

}

}

 

 

 

 

 

 

 

 

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-12 08:11

I finally got it!!!

 

I changed the way the JDBC driver was loaded by IReportJDBCConnector from

Class.forName( jdbDriver ) to

Class.forName( jdbDriver ).newInstance()

 

Now, I'm getting a succesful database connection.

 

Thanks a lot for your patience.

 

 

 

 

 

By: Rex Jun Cabanilla - rexjun

RE: Recital JDBC error - No suitable driver

2003-04-12 08:23

I guess I'll also need the source for IReportCompiler as well.

 

I get the same error "No suitable driver" from IReportCompiler when I try to compile a report with a Recital database connection.

 

 

 

 

By: Giulio Toffoli - gt78

RE: Recital JDBC error - No suitable driver

2003-04-13 13:01

You can fine IReportCompiler at:

 

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ireport/iReport/IReportCompiler.java

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...