[MonetDB-users] Connecting to MonetDB servers using JDBC
Hi, I'm trying to connect to the Monetdb using Java on Linux (Ubuntu 7.04/i386). I used the example java program given on the MonetDB site. $ javac -cp jdbcclient-1.6.jar:. MJDBCTest.java $ java -cp jdbcclient-1.6.jar:. MJDBCTest I'm getting a persistent error:. Exception in thread "main" java.sql.SQLException: java.net.URISyntaxException: Expected scheme name at index 0: :monetdb://127.0.0.1:50002/mytest2?lang=sql&user=monetdb at nl.cwi.monetdb.jdbc.MonetConnection.<init>(MonetConnection.java:217) at nl.cwi.monetdb.jdbc.MonetDriver.connect(MonetDriver.java:157) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at MJDBCTest.main(MJDBCTest.java:14) The Java code is attached below for reference: import java.sql.*;^M public class MJDBCTest {^M public static void main(String[] args) throws Exception {^M // make sure the driver is loaded^M Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");^M Connection con = DriverManager.getConnection("jdbc:monetdb://localhost/mytest2", "monetdb", "monetdb");^M Statement st = con.createStatement();^M ResultSet rs;^M ^M rs = st.executeQuery("SELECT * from foobar");^M // get meta data and print columns with their type^M ResultSetMetaData md = rs.getMetaData();^M for (int i = 1; i <= md.getColumnCount(); i++) {^M System.out.print(md.getColumnName(i) + ":" +^M md.getColumnTypeName(i) + "\t");^M }^M System.out.println("");^M // print the data: only the first 5 rows, while there probably are^M // a lot more. This shouldn't cause any problems afterwards since the^M // result should get properly discarded on the next query^M for (int i = 0; rs.next() && i < 5; i++) {^M for (int j = 1; j <= md.getColumnCount(); j++) {^M System.out.print(rs.getString(j) + "\t");^M }^M System.out.println("");^M }^M ^M // tell the driver to only return 5 rows, it can optimize on this^M // value, and will not fetch any more than 5 rows.^M //st.setMaxRows(5);^M // we ask the database for 22 rows, while we set the JDBC driver to^M // 5 rows, this shouldn't be a problem at all...^M rs = st.executeQuery("select * from foobar limit 2");^M // read till the driver says there are no rows left^M for (int i = 0; rs.next(); i++) {^M System.out.print("[" + rs.getString(1) + "]");^M System.out.print("[" + rs.getString(2) + "]\n");^M ^M }^M con.close();^M }^M } -- Home: http://btbytes.com Heart: http://sampada.net
Hi Pradeep, Can you please tell what Java you are using? I think java -version and javac -version will be enough. On 09-08-2007 15:22:06 +0530, Pradeep Gowda wrote:
Hi, I'm trying to connect to the Monetdb using Java on Linux (Ubuntu 7.04/i386).
I used the example java program given on the MonetDB site. $ javac -cp jdbcclient-1.6.jar:. MJDBCTest.java $ java -cp jdbcclient-1.6.jar:. MJDBCTest
I'm getting a persistent error:. Exception in thread "main" java.sql.SQLException: java.net.URISyntaxException: Expected scheme name at index 0: :monetdb://127.0.0.1:50002/mytest2?lang=sql&user=monetdb at nl.cwi.monetdb.jdbc.MonetConnection.<init>(MonetConnection.java:217) at nl.cwi.monetdb.jdbc.MonetDriver.connect(MonetDriver.java:157) at java.sql.DriverManager.getConnection(DriverManager.java:582) at java.sql.DriverManager.getConnection(DriverManager.java:185) at MJDBCTest.main(MJDBCTest.java:14)
The Java code is attached below for reference:
import java.sql.*;^M public class MJDBCTest {^M public static void main(String[] args) throws Exception {^M // make sure the driver is loaded^M Class.forName("nl.cwi.monetdb.jdbc.MonetDriver");^M Connection con = DriverManager.getConnection("jdbc:monetdb://localhost/mytest2", "monetdb", "monetdb");^M Statement st = con.createStatement();^M ResultSet rs;^M ^M rs = st.executeQuery("SELECT * from foobar");^M // get meta data and print columns with their type^M ResultSetMetaData md = rs.getMetaData();^M for (int i = 1; i <= md.getColumnCount(); i++) {^M System.out.print(md.getColumnName(i) + ":" +^M md.getColumnTypeName(i) + "\t");^M }^M System.out.println("");^M // print the data: only the first 5 rows, while there probably are^M // a lot more. This shouldn't cause any problems afterwards since the^M // result should get properly discarded on the next query^M for (int i = 0; rs.next() && i < 5; i++) {^M for (int j = 1; j <= md.getColumnCount(); j++) {^M System.out.print(rs.getString(j) + "\t");^M }^M System.out.println("");^M }^M ^M // tell the driver to only return 5 rows, it can optimize on this^M // value, and will not fetch any more than 5 rows.^M //st.setMaxRows(5);^M // we ask the database for 22 rows, while we set the JDBC driver to^M // 5 rows, this shouldn't be a problem at all...^M rs = st.executeQuery("select * from foobar limit 2");^M // read till the driver says there are no rows left^M for (int i = 0; rs.next(); i++) {^M System.out.print("[" + rs.getString(1) + "]");^M System.out.print("[" + rs.getString(2) + "]\n");^M ^M }^M con.close();^M }^M }
-- Home: http://btbytes.com Heart: http://sampada.net
------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
On 8/9/07, Fabian Groffen
Hi Pradeep, Can you please tell what Java you are using? I think java -version and javac -version will be enough.
Hi Fabian, Thanks for the quick reply. $ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing) $javac -version javac 1.6.0
On 09-08-2007 16:14:25 +0530, Pradeep Gowda wrote:
On 8/9/07, Fabian Groffen
wrote: Hi Pradeep, Can you please tell what Java you are using? I think java -version and javac -version will be enough.
Hi Fabian, Thanks for the quick reply.
$ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
$javac -version javac 1.6.0
Our JDBC driver can currently only be built with Java 1.4 or 1.5. The error you get is very weird, and not reproducable with Java 1.5 here. If I have some time I'll try to run it with Java 1.6 to see if I find the same problem. Is it an option for you to run Java 1.5?
On 8/10/07, Fabian Groffen
On 09-08-2007 16:14:25 +0530, Pradeep Gowda wrote:
On 8/9/07, Fabian Groffen
wrote: Hi Pradeep, Can you please tell what Java you are using? I think java -version and javac -version will be enough.
Hi Fabian, Thanks for the quick reply.
$ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
$javac -version javac 1.6.0
Our JDBC driver can currently only be built with Java 1.4 or 1.5. The error you get is very weird, and not reproducable with Java 1.5 here. If I have some time I'll try to run it with Java 1.6 to see if I find the same problem.
I recompiled the file and ran it with 1.5 version of javac & java respectively, and got the same error. pradeep@euler:~$ javac -version javac 1.5.0_11 pradeep@euler:~$ java -version java version "1.5.0_11" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03) Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing) I had no problems in connecting via jdbc (using the exact same libjdbc.jar file) in windows.
On 8/10/07, Pradeep Gowda
On 8/10/07, Fabian Groffen
wrote: On 09-08-2007 16:14:25 +0530, Pradeep Gowda wrote:
On 8/9/07, Fabian Groffen
wrote: Hi Pradeep, Can you please tell what Java you are using? I think java -version and javac -version will be enough.
Hi Fabian, Thanks for the quick reply.
$ java -version java version "1.6.0" Java(TM) SE Runtime Environment (build 1.6.0-b105) Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)
$javac -version javac 1.6.0
Our JDBC driver can currently only be built with Java 1.4 or 1.5. The error you get is very weird, and not reproducable with Java 1.5 here. If I have some time I'll try to run it with Java 1.6 to see if I find the same problem.
I recompiled the file and ran it with 1.5 version of javac & java respectively, and got the same error.
pradeep@euler:~$ javac -version javac 1.5.0_11
pradeep@euler:~$ java -version java version "1.5.0_11" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03) Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
I had no problems in connecting via jdbc (using the exact same libjdbc.jar file) in windows.
Also, compiling with Java 1.4 using GNU GCJ and running it with GNU GIJ gave the following error: Exception in thread "main" java.sql.SQLException: Maximum number of redirects reached, aborting connection attempt. Sorry. at nl.cwi.monetdb.jdbc.MonetConnection.<init>(MonetConnection.java:217) at nl.cwi.monetdb.jdbc.MonetDriver.connect(MonetDriver.java:157) at java.sql.DriverManager.getConnection(libgcj.so.70) at java.sql.DriverManager.getConnection(libgcj.so.70) at MJDBCTest.main(MJDBCTest.java:6)
On 10-08-2007 14:33:21 +0530, Pradeep Gowda wrote:
Also, compiling with Java 1.4 using GNU GCJ and running it with GNU GIJ gave the following error:
GCJ is not always fully compliant with Sun's Java. Anyway, the error hints me something might go wrong what we don't expect. Could you modify your original program to have "?debug=true" appended to the connection url? It produces a monet_xxxxxx.log file. Could you send it to me off-list?
Exception in thread "main" java.sql.SQLException: Maximum number of redirects reached, aborting connection attempt. Sorry. at nl.cwi.monetdb.jdbc.MonetConnection.<init>(MonetConnection.java:217) at nl.cwi.monetdb.jdbc.MonetDriver.connect(MonetDriver.java:157) at java.sql.DriverManager.getConnection(libgcj.so.70) at java.sql.DriverManager.getConnection(libgcj.so.70) at MJDBCTest.main(MJDBCTest.java:6)
On 10-08-2007 11:06:56 +0200, Fabian Groffen wrote:
On 10-08-2007 14:33:21 +0530, Pradeep Gowda wrote:
Also, compiling with Java 1.4 using GNU GCJ and running it with GNU GIJ gave the following error:
GCJ is not always fully compliant with Sun's Java. Anyway, the error hints me something might go wrong what we don't expect. Could you modify your original program to have "?debug=true" appended to the connection url? It produces a monet_xxxxxx.log file. Could you send it to me off-list?
On a second thought, I think I fixed this already. Which JDBC driver are you using? What sources did you compile it from? The current patchlevel of 1.6 Steadfast is 6, i.e: Driver: v1.6 (Steadfast_p6 20070720 based on MCL v1.0) This may have been fixed by this commit: date: 2007/07/17 09:46:42; author: mr-meltdown; A database name is optional. When it is unset it means the "current" being hosted by the database connected to. Allow urls and connections to be made with no database name specified. Print the current dbname on the JdbcClient welcome message so we know what we ended up connecting to. which was patchlevel 3.
participants (2)
-
Fabian Groffen
-
Pradeep Gowda