Results 1 to 10 of 10
  1. #1
    Join Date
    May 2009
    Posts
    20

    Unanswered: Source code for JDBC

    Hi, I'm looking for source code for the JDBC driver for MS SQL Server 2008. (If 2008 is not available, maybe I can work with 2005?) Where can I get it, along with simple instructions on how to compile it and where to install it.

    Thank you,
    Dave

  2. #2
    Join Date
    May 2009
    Posts
    20

    Source code for JDBC

    I need to modify the code somewhat, that's why I ask.

    Thank you,
    Dave

  3. #3
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    You will need to ask Microsoft but I highly doubt it that they are releasing the source code. They are not really known for their open source strategy.

    You can use the jTDS driver if you want to. It's open source, and if you really need to modify the source of the driver you could.

    Why do you think you need to modify the code?

  4. #4
    Join Date
    May 2009
    Posts
    20

    Source code for JDBC

    Thank you for the suggestion. I will trying to compile JTDS and see what I get.

    As for why: I need to modify the outbound queries from an application so that I can translate them into another language before they hit the database. I cannot change the application and so have to do this in a middle layer like JDBC.

    Thank you,
    Dave

  5. #5
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Quote Originally Posted by dave5555
    As for why: I need to modify the outbound queries from an application so that I can translate them into another language before they hit the database. I cannot change the application and so have to do this in a middle layer like JDBC.
    What do you mean with "another language"?
    I don't think SQL Server "speaks" something different than SQL.

    But maybe some of the "proxy" drivers out there might be a better start as they intercept the statements then do something with them (normally log them) and then hand them over to the "real" driver:

    Other projects that come to my mind are:

    SourceForge.net: JdbcProxy - To trace and stub JDBC calls
    SourceForge.net: Proxool: Proxy JDBC Connection Pool
    SourceForge.net: JDBC to JDBC bridge

    The JDBC driver framework might be an option as well:

    Then maybe other opensource drivers are better suited for this (which do not carry the full overhead of the Sybase/Microsoft protocol)

    There is a project on sourceforge which gives you the basic framework to built a driver, that might be of more help:

    SourceForge.net: jxDBCon - JDBC driver framework

    Or projects like:
    SourceForge.net: Modular JDBC SQL Engine (ModSQL)
    SourceForge.net: LDBC Liberty Database Connectivity

  6. #6
    Join Date
    May 2009
    Posts
    20
    This is extremely useful!! I will check out these options. But here is my specific question. (I've asked it before but with some testing, previously-recommended solutions are less optimal):

    I need to intercept queries coming from an application written in English into other languages (e.g. Spanish, Russian, etc) before they hit the database. The data in the database is changing but the application queries are not. So I need to intercept a query like "SELECT from shirts where color = 'red'" and translate it into "SELECT from shirts where color = ‘krasnii’" for a Russian version of the query.

    That's why I want to modify JDBC. I've had some compiling problems with JTDS so far, but will continue trying to debug. However, from all the approaches you recommended, which one has an API or source code available where I can write a method or function to intercept a query from an app, parse it, and replace the tokens that need to be translated with their foreign equivalents? I need a solution that can be fairly quickly implemented within the Microsoft SQL Server 2008 and Microsoft JDBC environment, ideally without Herculian efforts. Right now I’m testing on my laptop.

    Thank you,
    Dave

  7. #7
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Hmm, for that scenario "patching" the real driver is probably the best solution, as you still need to hand the query to the real backend and the query needs to be processed and everything.

    I don't think there is an easy solution for this.

    There are several API calls that you will need to intercept, from the top of my head I can think of:

    Statement.executeQuery(String)
    Statement.execute(String)
    Statement.execute(String, int)
    Statement.execute(String, int[])
    Statement.execute(String, String[])
    Statement.executeUpdate(String)
    Statement.executeUpdate(String, int)
    Statement.executeUpdate(String, int[])
    Statement.executeUpdate(String, String[])

    PreparedStatement.executeQuery()
    PreparedStatement.setString(int, String)
    PreparedStatement.setObject(int, String)
    CallableStatement.setString(String)
    CallableStatement.setObject(int, String)

    Connection.prepareStatement(String)
    Connection.prepareCall()

    But there might be more.

    How do you know which parts to replace in the input string (query)?

    If you want to get it right, you'll need to fully parse and analyze the statement (which columns are affected, what kind of value is supplied etc). and you need to consider prepared statements as well inside the setXXX() methods of PreparedStatement and CallableStatement (where you need to find out against which column the value is supposed to be matched)

    Or is the number of values that you need to replace very limited so that you can do a simple keyword lookup?

    What about the results that are returned?
    Do you need to change the data there as well?

    That will most probably be a very complicated thing to do because you need to intercept the streaming of the data from the server to the application unless you use the full buffering of the results which is the default for the jTDS driver, but then the application can turn that off, and you might not notice that (but I have not enough knowledge of the of the internals of the driver to really judge this.

  8. #8
    Join Date
    May 2009
    Posts
    20
    Thank you very much for this. Let me explore. However, are you sure that doing this through the items you previously recommended would be less optimal? For example, what about the JDBC wrappers that you recommended? Can you modify their source code so that the query is intercepted, modified, and then sent to the JDBC driver?
    I'm just looking for the fastest way, which is also most compatible with different drivers, Operating Systems, etc.

    Thank you very much,
    Dave

  9. #9
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Quote Originally Posted by dave5555
    Thank you very much for this. Let me explore. However, are you sure that doing this through the items you previously recommended would be less optimal? For example, what about the JDBC wrappers that you recommended? Can you modify their source code so that the query is intercepted, modified, and then sent to the JDBC driver?
    I don't know I have never looked at either source code.
    The number of API calls is identical whether you use the wrapper or the real driver.
    And the problem of manipulating the returned data is also the same.
    You will need to try for yourself.

  10. #10
    Join Date
    May 2009
    Posts
    20
    Thank you for this. I am trying to modify the JTDS driver now and will see how it works. In the meantime, let me ask about what you said earlier. I do want to modify the results coming back, i.e. translate them back into English so the application can manage them. Can't I just intercept the result set on its way back (i.e. modify some other methods in JTDS)? Won't they go back through the JTDS/JDBC driver? Can the application can turn it off...as you suggest?

    Thank you,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •