port number of database produce error message - jdbc

I'm writing a simple java program (Jcreator as my IDE) to connect with Oracle Database (using SQL Plus / Oracle 10g). I first downloaded the jar file and copied it into bin directory in oracle directory. Then, I added the jar file to my JDK and wrote this code :
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con=DriverManager.getConnection(
"jdbc:oracle:thin:#localhost:1521:amani","system","a123");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from emp");
while(rs.next())
System.out.println(rs.getInt(1)+" - "+ rs.getString(2)+" - "+rs.getInt(3)+"\n");
The problem is when I use the default port number 1521, I do not get any results and no error messages appear.
and I know that I'm supposed to use my own database port number which is 1158, but then I get
java.sql.SQLException: Io exception: Bad packet type
What am I doing wrong, can someone help?

I don't know Java so - the following might be irrelevant nonsense so I apologize if that's the case.
Anyway, shortly: 1521 is most probably the port you should use (not 1158). Credentials you provided (username = system, password = a123) are wrong; use username = scott, password = tiger instead
A longer version of the above statement: you should have access to the database; seeing your code, it is installed on your own computer. Is it up and running, i.e. can you connect to it via SQL*Plus?
Saying that you are
supposed to use my own database port number which is 1158
well, I doubt that. If you installed everything by default, then your database port number is 1521, while 1158 is reserved for OEM (Oracle Enterprise Manager database console) so I don't think that 1158 is what you should use. See Managing Oracle Database Port Numbers.
Furthermore, is your database name really "amani"? That's what this
"jdbc:oracle:thin:#localhost:1521:amani","system","a123"
-----
this
suggests. In order to get its port, TNSPING it using command prompt (I've removed unnecessary part of the output): I can't tnsping amani (obviously, I don't have access to it)
c:\Temp>tnsping amani
TNS-03505: Failed to resolve name
but I can tnsping my own XE database:
c:\Temp>tnsping xe
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = my-laptop)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))
OK (110 msec)
See? It is "OK", and its port is 1521. Do it on your computer in order to find that information.
Finally, username and password: you used one of special, most powerful users in your database, SYSTEM (another one is SYS). It doesn't contain the EMP table - it belongs to user SCOTT (whose default password is TIGER).
As you're on Oracle 10g, if I remember well, SCOTT is one of pre-installed schemas so you should be able to connect to it. Check it as following: on my XE, I'm connected as SYS:
SQL> select username, account_status from dba_users;
USERNAME ACCOUNT_STATUS
------------------------------ --------------------------------
SYS OPEN
SYSTEM OPEN
ANONYMOUS OPEN
SCOTT LOCKED
HR OPEN
<snip>
SQL> alter user scott account unlock;
User altered.
SQL> alter user scott identified by tiger;
User altered.
SQL> connect scott/tiger#xe
Connected.
SQL> select count(*) From emp;
COUNT(*)
----------
12
SQL>
I hope you understood what I did.
That much about Oracle part of the story; I really wouldn't know what to do if that doesn't help, in order to make your Java side work. Hopefully, someone else will be able to assist.

Related

I install oracle client 11g on my machine .I am not give any username and password of course I am not get that window at initialisation time

How connect to the db .I am tried with the following username and passwords system/manager ,scott/tiger etc .But no luck I am still not connected to the db.And also I am getting TNS:Protocol adapter error. I am not understanding why? I also gone through the services for start/restart But there is no at least one single Oracle service file.How I am getting this oracle services as well as how I connect to the db.Please some body help me. My system operating system windows XP.. I am installing oracle client 11g on windows Xp operating system.
Oracle client is software that allows a remote computer to talk to Oracle. If you were to write a piece of software that communicated with the database, you would use the Oracle Client to facilitate that communication.
If you need oracle database in your machine you can go for Oracle database version like Express edition and Enterprise, standard edition. You can't create any database using the oracle client software.
Note : While installing oracle client(any version) it won't ask any username and password.
Steps to connect Oracle client to Oracle database
Consider your oracle server tnsname like below
ORA11 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = ORA11)
)
)
Place above tnsname text into your tnsname.ora file (C:\app\oracle\product\network/admin/tnsnames.ora)
After that check your sql*plus prompt like
tnsping databasename
sample output
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS= (PROTOCOL=TCP) (HOST=gracelan)
(PORT=1525)) (CONNECT_DATA= (SID=GRA901m)))
OK (80 msec)
connect username/password#dbname
can you please provide your tnsname ping output.
Use your server Name like tnsping orcl in cmd.exe
When ever you want to connect dbserver from dbclient we must know the username and password.That are all knows to the who install the Database server not Database client. From where ever we want to connect to the db we must and should know the username and password .i.e either from dbserver or dbclient.IN OTHER words when installing oracle client we don't enter any username and passwords.Because in client there is no database .we just connect the server db only.The password and username knows whose install DB server not client.From client we connect the server by using server username and server passwords...

How do I connect to the Database on a different server?

I have a machine A which has DB server on it.
I have a machine B which has Oracle Client installed on it.
I modified the tnsnames.ora file in machine B by adding the following:
TRIAL1 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = machineName.example.com)(PORT = 1521)(QUEUESIZE=100))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = Trial1.world)
)
)
Yet, I cannot run the command sqlplus name/pwd#trial as sysdba on machine B successfully. It throws an error stating "insufficient privileges". Are there any modifications needed on the sqlnet.ora or tnsnames.ora file on machine A?
In order to be able to connect remotely as sysdba you need to grant that system privilege to user that needs to do that.
grant sysdba to name;
From now on you can connect from any machine using sqlplus name/pwd#trial1 as sysdba. The name is the username defined in the database that you connect to, no matter from which OS account you connect or from which machine you connect, as long as the connection can be made.
Question that remains is: do you need to work as sysdba in that database. Don't do that unless you know what you are doing. Effectively you work as SYS, the owner of the catalog. The slightest typo can make your database dead as a dodo.
For most, even a regular dba account is already too much. Create a regular account ASAP give it the needed privileges and use that one to do your work. The needed privileges are the minimal privs needed to do the job (create session, create table, create procedure etc. (almost certainly not dba))

Oracle 11g database not connecting

i installed oracle 11g database express edition on my windows 7 (32 bit) pc . It was successfully installed but now when i try to open it , Firefox gives me following error.
"unable to connect."
So please reply to this post as soon as possible to open Oracle as without this , i can't go ahead in learning it. I m just a beginner.
Check if u can open SQLPLUS
if yes, change the port of ORACLE web server by using
connect / as sysdba
DBMS_XDB.sethttpport('9090');
open run SQL command line or in your cmd writes: sqlplus "/ as sysdba"
for both cases:
SQL> conn
Enter user-name:
Enter password:
In SQL DEVELOPER
Default connection for oracle 11g
go to connection>New Connection
Connection Name = HR or Use any name
User name = hr
Password = Your Password (This is the password that you selected during the installation of the of Oracle 11g)
Check the "Save" option
role: default
port 1521
SID : orcl
If you want to create the SYSDBA Account ( Administrator account)
Connection Name = admin ORCL or Use any name
User name = sys
Password = Your Password (This is the password that you selected during the installation of the of Oracle 11g)
role: sysdba( from the drop down)
port 1521
SID : orcl
TEST and Save Connect
Just in case if your HR account is locked because you have connected multiple number of times than you can fix this by logging into your SYS DBA account
In the objects list on your list go to the OTHER USERS and
GO to HR Account > RT Click
EDIT USER
Choose the password youlike
and UN CHECK The account locked and Uncheck the Password Expired options if they are checked in
This happens when the you install as a user and not as admin. Even if u have admin privileges, it won't do.
Also, after this error comes then the issue is that the port 8080 is being used by another application.
1.) First of all, stop that app.
2.) Rest Oracle Port
SQL> begin
2 dbms_xdb.sethttpport('9090');
3 end;
4 /
PS: I read one thread it says that don't use # in the password also.
Hope it helps :)

Unable to connect to oracle with different OS user accout

I have installed Oracle on Ubuntu with OS user oracle. When I try to connect to Oracle when logged on as different OS user (other than oracle), I get error:
SQL> connect user1/user1#orcl
ORA-12154: TNS:could not resolve the connect identifier specified
However, if I don't mention Oracle SID then I don't get any error:
SQL> connect user1/user1
Connected to:
Oracle Database
SQL>
I have declared ORACLE_HOME and SID in the user profile. But it did not work. Can someone please help me to understand the issue.
In a sense you don't really have a problem; you can connect locally using the ORACLE_HOME and ORACLE_SID environment variables, which is fine.
When you use the connect user1/user1#orcl version, the orcl is not your SID; as explained in the documentation it is an 'Oracle Net connect identifier'.
connect_identifier
An Oracle Net connect identifier. The exact syntax depends on the
Oracle Net configuration. For more information, refer to the Oracle
Net manual or contact your DBA. SQL*Plus does not prompt for a service
name, but uses your default database if you do not include a connect
identifier.
So you are connecting over a network connection, even though its to the same host, rather than internally using IPC. You don't even need to have ORACLE_SID set when you do that, because that is used for IPC and isn't part of the network connection.
Now, the connect identifier may well actually be the same string as your SID, but it doesn't have to be. Usually when you're using a single term like orcl you're using a 'net service name' which is defined in your tnsnames.ora file. (Depending on how the naming methods are configured in your sqlnet.ora, which determines how the connect identifier is resolved; but this is still the most common configuration I think).
The Oracle Net configuration can be configured using the netca configuration assistant, as the oracle user, though you can create a private tnsnames.ora to override that.
See the Oracle Net admin guide for more about how connectivity works and is configured, and the SQL*Plus user guide for a shorter version.
In order for your user1/user1#orcl connection to work you would need a tnsnames.ora entry looking something like:
orcl =
(DESCRIPTION =
(ADDRESS = (PROTOCOL=tcp)(HOST=my_host)(PORT=1521))
(CONNECT_DATA = (SERVICE_NAME = orcl)))
... where my_host is the DNS name or IP address of your Oracle server, and 1521 is the port the listener is configured to run on. (The listener has to be running for you to be able to connect this way, too). The SERVICE_NAME is not necessarily the same as your SID either, but depends on the database configuration; the lsnrctl status command will show what service names are available.
The ORA-12154 error is telling you that you either don't have a tnsnames.ora file at all, or that it doesn't contain an entry for the alias orcl.
As #a_horse_with_no_name points out, there are other forms of connect identifier, and you don't necessarily need a tnsnames.ora file for a network connection; the options are explained here. I've just focused on the one you were trying to use. You don't necessarily need to use any of them though since you are able to connect locally.

Can't create Database Link to remote DB in Oracle-DB

We have a CRM system in our company, which uses an Oracle 11g database. It is developed by a third party vendor.
We do not have access to the server which runs the CRM system. But nevertheless, we have working DBA login data available to us (SYS user). It consists of:
server IP: 172.1.2.3
port: 1521
SID: abc
user: sys
password: *
We can use this to access the DB with Oracle SQL Developer 3.1 (Connections >> Properties)
Now parts of the data must be copied out of the CRM-database into an other Oracle database, which resides on another server.
To my understanding, I'd need to create a database link in my target database. I tried something like this:
CREATE PUBLIC DATABASE LINK xxx CONNECT TO sys IDENTIFIED BY ***** USING 'MYTNSENTRY'
My tnsnames.ora is as follows:
MYTNSENTRY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.1.2.3)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = abc)
)
)
.... and my listener.ora look like this:
MYLISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=172.1.2.3)(PORT=1521))
))
SID_LIST_MYLISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=MYTNSENTRY)
(ORACLE_HOME=C:\somepath) # path to Oracle home of target DB
(PROGRAM=extproc)))
Is PROGRAM=extproc the right choice? There are a couple of other programs to pick. I couldn't even start the listener with lsnrctl because it could not "verify the user" or something. Ironically, the listener-setup and database link to a MS SQL server work smoothly.
Now despite lacking some vital information about the CRM DB system, one can still connect to the DB in SQL Developer. Shouldn't it also be possible to make a connection between two Oracle DBs? Please help me with the setup and the creation of the database link.
----- EDIT: --------
Alex Poole's hint helped me get it to work. I used
show parameters service_names;
to get the full service name. It has the form abc.def, with def being the domain. Thusly, I added the domain name to the TNS alias in tnsnames.ora:
MYTNSENTRY =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 172.1.2.3)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = abc.def)
)
)
The connection can be tested with tnsping MYTNSENTRY on the command prompt of the target DB server. The tnsnames.ora is local. However, I deleted all changes to the "local" listener.ora, since the listener indeed resides on the CRM server.
The SQL command is mostly unchanged, but now the connection works:
CREATE PUBLIC DATABASE LINK xxx CONNECT TO some_user IDENTIFIED BY ***** USING 'MYTNSENTRY'
You've said the SID is abc, but in your tnsnames.ora you've got the SERVICE_NAME in the CONNECT_DATA section. They are not always the same thing - see this question, or this Ask Tom entry. You haven't actually said what error you're getting, but just changing that to SID = might make a difference.
The listener.ora, and indeed the listener, are on the server that hosts the CRM database, not on the one that hosts your 'target' database. As you can connect from SQL Developer that is apparently already configured. The tnsnames.ora does need to be local.
But if you do know the service_name for the CRM database you can skip that and use the EZCONNECT syntax to define everything in the link:
CREATE PUBLIC DATABASE LINK xxx
CONNECT TO non-sys IDENTIFIED BY *****
USING '//172.1.2.3:1521/service_name';
Check your SQL Developer configuration to see if that is already using the service name, rather than SID, and if not you'll need to discover it. If you had access to the CRM server you could use lsnrctl to find the service names that are registered, but as you don't seem to you will need to connect to the database and run show parameters service_names or select value from v$parameter where name = 'service_names';.
You need more privileges to create a public link than a private one, and public is potentially less secure as it exposes your CRM database to anyone on your target one. So I'd only make it public if really needed, and either way connect to a read-only account if you're able to create one.
Also note that if your target database has global_names set to true the database link name has to match the remote service name.
Not only should you NOT connect as SYS unless necessary, you CANNOT connect as SYS over a database link.

Resources