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

  • Home
  • SEARCH
  • 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 6592385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:32:53+00:00 2026-05-25T17:32:53+00:00

I have a function to get JDBC metadata through clojure-sql (ns relink (:require [clojure.contrib.sql

  • 0

I have a function to get JDBC metadata through clojure-sql

(ns relink
     (:require
      [clojure.contrib.sql :as sql]
      [clojure.string :as str]
      ))

(let [db-host "localhost"
      db-port 1433
      db-name "databasename"]

(def db {:classname "com.microsoft.sqlserver.jdbc.SQLServerDriver"
         :subprotocol "sqlserver"
         :subname (str "//" db-host ":" db-port)
         :databasename db-name
         :user "user"
         :password "password"}))

(defn get-table-metadata
    "Take database spec, return all table names from the database metadata"
    [db]
    (sql/with-connection db
      (doall
                (resultset-seq                 
                    (.getTables
                      (.getMetaData (sql/connection))
                     nil nil "%" (into-array '("TABLE")))))))

(get-table-metadata db)

Now I want to extend that function to use other SQL metadata, by wrapping the java method call in a clojure function as parameter, to look something like:

(get-sql-metadata db .getTables nil nil "%" (into-array '("TABLE")))

There’s seems no way to get this done without putting (.getMetaData (sql/connection)) inside the function parameter as well.

(get-sql-metadata db #(.getTables (.getMetaData (sql/connection)) nil nil "%" (into-array '("TABLE"))))

However, I would like to abstract this away inside the get-sql-metadata function, since it’s the same for all metadata method calls.

I’ve tried rewrite the part within resultset-seq with doto, .., -> and (. notations but could get none of them to work.

What did I miss ?

UPDATE:
The following solution works, but there’s some hacking needed. I can’t believe the reflection in str-invoke should be needed, so I won’t post it as an answer.

(defn str-invoke [instance method-str & args]
            (clojure.lang.Reflector/invokeInstanceMethod 
                instance 
                method-str 
                (to-array args)))

(defn get-sql-metadata
    "Take database spec, metadata method (as string) and method parameters"
    [db method & args]
    (sql/with-connection db
      (doall
                (resultset-seq                 
                   (apply str-invoke
                     (.getMetaData (sql/connection))
                     method args)))))

(get-sql-metadata db "getTables" nil nil "%" (into-array '("TABLE")))

The problem seems to be that apply is needed,but can’t be used on the . form.

  • 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-25T17:32:54+00:00Added an answer on May 25, 2026 at 5:32 pm

    As making get-sql-metadata a function will cause clojure to evaluate arguments before applying the function it is impossible to pass it an “unknown” symbol like .getTables which can’t be evaluated to the function.

    In macros on the otherhand evaluate arguments aren’t evaluated before aplying the macro.
    So making the function a Macro would allow you to do this.

    like:

    (defmacro get-sql-metadata [db method & args] 
      `(with-connection 
        ~db 
        (doall 
          (resultset-seq 
            (~method 
              (.getMetaData (connection)) 
              ~@args)))))
    

    And of course there is the possibility of transforming the method call into a clojure function by using the macro memfn, but i don’t think that’s what you want

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

Sidebar

Related Questions

I already have a function to get substring of a string void subString(char* buffer,
I have a function where I get a list of ids, and I need
I have the following function: //Function to get random number public static int RandomNumber(int
I have a via with some jQuery function to get value from HTML element
I have a javascript/jQuery block as a callback after $.get function: function myCallBack(data, textStatus)
I'm trying to get rid of floats in my functions. I have one function
hey guys, I am starting to get frustrated. I have a function I am
I have a javascript function generateGraph() { ... jQuery.get('chart.php?month='+month+'&year='+year); document.getElementById('graph').src = 'charts/'+month+'_'+year+'.png'; ... }
I have an org.springframework.jdbc.object.StoredProcedure which I am using to call a DB function. I
hello i want i have function to get paragraph of selected text. this is

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.