为什么我不能使用SQLcl通过jdbc连接 [英] Why can't I connect via jdbc using SQLcl

查看:85
本文介绍了为什么我不能使用SQLcl通过jdbc连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用SQLDeveloper连接到远程数据库.

I can connect to a remote database using SQLDeveloper.

我正在尝试从命令行使用sqlcl连接到同一数据库,但是出现错误.

I am trying to connect to the same database using sqlcl from the command line, but I am getting an error.

这是我正在运行的命令:

Here is the command that I am running:

/bin/sql username/pass@delphix-vdb-n-1.va2.b2c.nike.com:1521/vdbsl14 

我也尝试过:

/bin/sql username/pass@//delphix.......etc.

这是我收到的错误:

SQLcl: Release 4.2.0.16.131.1023 RC on Wed Jun 15 11:36:33 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

  USER          = username
  URL           = jdbc:oracle:thin:@delphix-vdb-n-1.va2.b2c.nike.com:1521/vdbsl14
  Error Message = Listener refused the connection with the following error:
ORA-12514, TNS:listener does not currently know of service requested in connect descriptor
Username? (RETRYING) ('username/*********@delphix-vdb-n-1.va2.b2c.nike.com:1521/vdbsl14'?) 

此外,在SQLDeveloper中,我只在"custom jdbc url"下输入以下内容,并且连接没有任何问题,因此我希望可以使用相同的URL通过命令行进行连接,但到目前为止,它不起作用:

Also in SQLDeveloper, I just enter the following under "custom jdbc url" and it connects without any issue, so I was hoping I could connect via the command line using the same URL but so far, it is not working:

jdbc:oracle:thin:@delphix-vdb-n-1.va2.b2c.nike.com:1521:vdbsl4

推荐答案

看起来您的SID和服务名称不同.在SQL Developer中,您似乎正在使用SID(至少在您显示的自定义JDBC URL中),如:vdbsl4中的冒号所示.

It looks like your SID and service name are not the same. In SQL Developer you seem to be using the SID - at least in the custom JDBC URL you showed - as denoted by the colon in :vdbsl4.

您的SQLcl URL使用的是服务名称,如/vdbsl14中的斜杠所示.在该URL中使用SID代替(即,将/更改为:)应该起作用,因为它使用的是JDBC:

Your SQLcl URL is using the service name, as denoted by the slash in /vdbsl14. Using the SID instead (i.e. changing the / to :) in that URL should work since it's using JDBC:

sqlcl username/pass@delphix-vdb-n-1.va2.b2c.nike.com:1521:vdbsl14

或者(在我看来,最好是找出您的服务名称实际上是什么).如果您对数据库具有足够的特权,则可以从SQL Devleoper中执行show parameters service_names,或者如果您可以DBA身份访问服务器,则可以执行lsnrctl services,甚至在有TNS别名的情况下也可以查看tnsnames.ora.定义显示服务名称. (listener.ora可能无济于事,但可能会给出提示,或者如果您很幸运,请显示默认的服务名称.)

Alternatively (and preferably, in my opinion) find out what your service name actually is. If you have sufficient privileges on the database you can do show parameters service_names from SQL Devleoper, or if you have access to the server as DBA you can do lsnrctl services, or even look at the tnsnames.ora in case there is a TNS alias defined that shows the service name. (listener.ora isn't likely to help, but could give hints or if you're lucky show a default service name).

您可以在JDBC URL中将该服务名称用作/service_name.

You can use that service name in a JDBC URL, as /service_name.

您还可以使用SQLcl(或SQL * Plus)中的TNS别名.您可能已经有tnsnames.ora可用;如果不是,您也许可以从服务器复制它,也可以创建自己的服务器.可以引用SID或服务名称.

You can also use a TNS alias from SQLcl (or SQL*Plus). You may already have a tnsnames.ora available; if not you might be able to copy it from your server, or create your own. That can refer to the SID or the service name.

您甚至可以将完整的TNS描述传递给SQL * Plus(不确定SQLcl),但这有点令人不愉快.如果您没有/想要tnsnames.ora,则可以使用'easy connect'语法,与用于SQLcl的语法相同-但必须作为服务名称,它不允许使用SID.

You can even pass a full TNS description to SQL*Plus (not sure about SQLcl) but that's a bit unpleasant. If you don't have/want a tnsnames.ora you can use 'easy connect' syntax, which is the same as you're using for SQLcl - but that has to be the service name, it doesn't allow SIDs.

这篇关于为什么我不能使用SQLcl通过jdbc连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆