Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Command line works, IDE fails

2 views
Skip to first unread message

Joseph Gilmour

unread,
Jan 13, 2002, 6:37:55 AM1/13/02
to
OK, I'm a bit of a newbie so be gentle. Downloaded Forte CE and Eclipse
(V2.0 build 20011219) to see what they're like. Created a small test
program (code below) that just connects to a McKoidb
(http://www.mckoi.com/database) database (based on the samples supplied)
gets a little info then exits. When I run it in either Forte or Eclipse
it dumps this;

java.lang.StringIndexOutOfBoundsException: String index out of range: -1

at java.lang.String.substring(String.java:1525)
at com.mckoi.database.jdbc.MDriver.connectToLocal(MDriver.java:195)
at com.mckoi.database.jdbc.MDriver.connect(MDriver.java:374)
at java.sql.DriverManager.getConnection(DriverManager.java:517)
at java.sql.DriverManager.getConnection(DriverManager.java:177)
at DBTest.main(DBTest.java:20)
Exception in thread "main"

If I run it from the command line then it works. It doesn't make any
difference if I compile in the IDE or commande line. I've played around
with classpaths and compiler options but can't seem to get anywhere.
I'd rather be able to run my programs from the IDE rather than test at a
command line.

Any help is appreciated.

Here's the code;
----------------------------------------------------------------
import java.sql.*;

public class DBTest {
public static void main(String[] args) {
try {
Class.forName("com.mckoi.JDBCDriver").newInstance();
}
catch (Exception e) {
System.out.println(
"Can't register JDBCDriver");
return;
}
String url = "jdbc:mckoi:local://DB.conf";
String username = "joe";
String password = "joe";

// Make a connection with the database.
Connection connection;
try {
connection = DriverManager.getConnection(url, username, password);

}
catch (SQLException e) {
System.out.println(
"Unable to make a connection to the database.\n" +
"The reason: " + e.getMessage());
return;
}

System.out.println();

try {
// Create a Statement object to execute the queries on,
Statement statement = connection.createStatement();
ResultSet result;

// How many rows are in the 'Person' table?
result = statement.executeQuery("SELECT COUNT(*) FROM tst1");
if (result.next()) {
System.out.println("Rows in 'Person' table: " + result.getInt(1));
}
System.out.println();

// Close the statement and the connection to end,
statement.close();
connection.close();

}
catch (SQLException e) {
System.out.println(
"An error occured\n" +
"The SQLException message is: " + e.getMessage());
return;
}
}
}
----------------------------------------------------------------
TIA
Joe Gilmour

Marshall Spight

unread,
Jan 13, 2002, 9:14:31 AM1/13/02
to
"Joseph Gilmour" <jgilmour@-DONTSPAMME-bigpond.net.au> wrote in message news:3C4170EC.8011D9AA@-DONTSPAMME-bigpond.net.au...

> OK, I'm a bit of a newbie so be gentle. Downloaded Forte CE and Eclipse
> (V2.0 build 20011219) to see what they're like. Created a small test
> program (code below) that just connects to a McKoidb
> (http://www.mckoi.com/database) database (based on the samples supplied)
> gets a little info then exits. When I run it in either Forte or Eclipse
> it dumps this;
>
> java.lang.StringIndexOutOfBoundsException: String index out of range: -1
>
> at java.lang.String.substring(String.java:1525)
> at com.mckoi.database.jdbc.MDriver.connectToLocal(MDriver.java:195)
> at com.mckoi.database.jdbc.MDriver.connect(MDriver.java:374)
> at java.sql.DriverManager.getConnection(DriverManager.java:517)
> at java.sql.DriverManager.getConnection(DriverManager.java:177)
> at DBTest.main(DBTest.java:20)
> Exception in thread "main"

That looks like a bug in your driver, frankly. Is the URL well-formed?


> If I run it from the command line then it works. It doesn't make any
> difference if I compile in the IDE or commande line. I've played around
> with classpaths and compiler options but can't seem to get anywhere.
> I'd rather be able to run my programs from the IDE rather than test at a
> command line.

This is likely to be a configuration issue. You need to know
where all you class files are and where all your jar files are. It'll likely
be different for the IDEs and for the command line.


Marshall


Marshall

Paul de Vrieze

unread,
Jan 14, 2002, 11:40:21 AM1/14/02
to
Marshall Spight <msp...@dnai.com> wrote:

> This is likely to be a configuration issue. You need to know
> where all you class files are and where all your jar files are. It'll likely
> be different for the IDEs and for the command line.

Are the current dirs on both environments the same? Often the IDE starts
with a different current dir than the command line (which starts at the
root of your project). You could look for the option to set the current
dir. I don't know forte that well, but in netbeans (on which forte is
based) you can set the current dir as a property to the class file that is
your projects main.

Paul

--
___
/~~~\ | Paul de Vrieze
| O-O | | Student of information management and technology
| _ | | Mail: Pa...@devrieze.net
\___/ | Homepage: http://www.devrieze.net

0 new messages