Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • jdbc help

    Stata community: I am attempting to connect to a db using jdbc using the following:

    local jar "mssql-jdbc-12.4.2.jre11.jar"
    local driverc "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    local url "jdbc:sqlserver://{HOST}:1433/{DB}"
    local user "{USER}"
    local pass "{PW}"

    jdbc add MyDB, jar("`jar'") driverclass("`driverc'") url("`url'") user("`user'") password("`pass'")

    jdbc connect MyDB

    jdbc showtables

    connection failed
    The port number 1433/{DB} is not valid.
    r(681);

    I've obscured the actual HOST, USER, PW, and DB in the above. As you can see I get the error that the port number 1433/DSN is not valid. I've been through the documentation, read through the threads, and done my own research, but I don't know why this fails to execute. If you've connected using the MS jdbc driver 12.4.2 I'd appreciate any guidance here. Thanks in advance.

    Running Stata 18 on Macbook Pro M1 Max Sonoma 14.3

  • #2
    Just a quick follow up. Using the same host, db, port, user, pw I can connect using DBeaver's mssql jdbc. I'd rather be able to read data directly into Stata rather then use a workaround like DBeaver, though. Thanks again in advance to the Stata community.

    Comment


    • #3
      I figured it out. I needed to make the jdbc url more explicit: local url "jdbc:sqlserver://HOST:1433;databaseName=DBNAME;encrypt=true;trustSe rverCertificate=true;readonly=true"
      Then it worked.

      Comment

      Working...
      X