Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3341500
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:43:47+00:00 2026-05-18T00:43:47+00:00

I have a simple Clojure program that queries an Oracle database and prints out

  • 0

I have a simple Clojure program that queries an Oracle database and prints out results in a comma delimited format. This program works just fine running it normally through Clojure.main. I want to compile this program and followed the instructions from here:

http://java.ociweb.com/mark/clojure/article.html#Compiling

I compiled and ran another simple program using this method described just fine. So I don’t think this has anything to do with this method of compiling. This program compiles just fine but when I attempt to run the compiled class it returns this error:

Exception in thread “main”
java.lang.RuntimeException:
java.lang.RuntimeException:
java.sql.SQLException: Exhausted
Resultset
at clojure.lang.LazySeq.sval(LazySeq.java:47)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.RT.seq(RT.java:440)
at clojure.core$seq__4245.invoke(core.clj:105)
at bill.myquery$dump_db_csv__24.invoke(myquery.clj:27)
at bill.myquery$main_49.invoke(myquery.clj:41)
at clojure.lang.AFn.applyToHelper(AFn.java:171)
at clojure.lang.AFn.applyTo(AFn.java:164)
at bill.myquery.main(Unknown Source)
Caused by: java.lang.RuntimeException:
java.sql.SQLException: Exhausted
Resultset
at clojure.lang.LazySeq.sval(LazySeq.java:47)
at clojure.lang.LazySeq.seq(LazySeq.java:56)
at clojure.lang.Cons.next(Cons.java:37)
at clojure.lang.RT.boundedLength(RT.java:1128)
at clojure.lang.RestFn.applyTo(RestFn.java:135)
at clojure.core$apply__4370.invoke(core.clj:438)
at clojure.core$resultset_seq_6276$thisfn_6290$fn__6291.invoke(core.clj:3842)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
… 8 more Caused by: java.sql.SQLException: Exhausted
Resultset
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.jdbc.driver.OracleResultSetImpl.getObject(OracleResultSetImpl.java:900)
at clojure.core$resultset_seq__6276$row_values_6284$fn_6286.invoke(core.clj:3839)
at clojure.core$map_5053$fn_5055.invoke(core.clj:1760)
at clojure.lang.LazySeq.sval(LazySeq.java:42)

Here it is:

(ns bill.myquery (:gen-class))

;; Import java.sql classes
(import '(java.sql DriverManager Connection PreparedStatement ResultSet))

;; load jdbc/odbc driver
(. Class forName "oracle.jdbc.driver.OracleDriver")

(def dbname "myOracleServer:1522:myOracleDatabase")
(def service_account "account")
(def service_password "password")

(def conn (. DriverManager (getConnection (str "jdbc:oracle:thin:@" dbname) service_account service_password)))

(def sql "
        SELECT name, address, phone
        FROM addresss_book
        ORDER BY name")

;; Function to dump data with comma delimited fields
(defn dump-db-csv [db]
  (doseq [rec db] ;; for all rows
    (doseq [[key value] rec] ;; for all fields
        (if (= key :phone) ;; if last field
              (print (.trim (str value))) ;; don't print comma
              (print (format "%s%s" (.trim (str value)) ","))))
    (println)))

;; Execute query and get recordset
(def rs (.. conn (prepareStatement sql) (executeQuery)))

;; convert recordset to sequence
(def rset (resultset-seq rs))

;; Main call the function to print rows
(defn -main (dump-db-csv rset))

;; close the recordset
(. rs (close))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:43:47+00:00Added an answer on May 18, 2026 at 12:43 am

    Don’t use def – everything from the top level is executed at class load time (or even at compile time), so you close result set (rs) before running -main. Always open and close connection in a single function – it will prevent a lot of errors.

    Also consider using clojure.contrib.sql. Nice examples can be found at wikibooks.

    For both methods don’t forget to use doall for any possible lazy sequences.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should simple JavaBeans that have only simple getters and setters be unit tested?? What
I have a simple webform that will allow unauthenticated users to input their information,
I have a simple 2-column layout with a footer that clears both the right
i have a simple clojure syntax problem (bc i am new to the language).
I am a beginner in Clojure, and I have a simple (stupid) question. I
I am a beginner in Clojure, and I have a simple question Lets say
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement
I develop tools in Autodesk Maya. Many of the tools I build have simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.