0

I've created the Informix database as described in my previous question (Create Informix database). Now I need to have JDBC access to it. How should I configure the Informix database server?

I can create a database, tables, and run any queries via dbaccess utility.

I've attempted to connect to it via JDBC with the following connection string (testdatabase was created by dbaccess):

jdbc:informix-sqli://localhost:8202/test:INFORMIXSERVER=myserver;user=informix;password=1111;

The result is:
Connection refused java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)

Ok, since user=informix and password=1111 are local Linux user and password, it looks like I have to add a user properly.

So, I've changed in $INFORMIXDIR/etc/onconfig the string
from USERMAPPING OFF
to USERMAPPING ADMIN.

Then I connected to test database via dbaccess and create user according to CREATE USER statement doc:

CREATE USER mary WITH PASSWORD "joebar" PROPERTIES UID 44567 GROUP(1234)

Again, no success with it:

jdbc:informix-sqli://localhost:8202/test:INFORMIXSERVER=myserver;user=mary;password=joebar;

The result is the same:
Connection refused java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)

Furthermore, I can't use this user to connect via dbaccess. Literally:

  • dbaccess
  • DBACCESS >> Connection
  • CONNECTION >> Connect
  • SELECT DATABASE SERVER >> myserver
  • USER NAME >> [RETURN] (type nothing)
  • SELECT DATABASE >> choose test@myserver

The result is: Database selected.

But if I'm trying to use created user:

  • dbaccess
  • DBACCESS >> Connection
  • CONNECTION >> Connect
  • SELECT DATABASE SERVER >> myserver
  • USER NAME >> mary
  • PASSWORD >> joebar
  • SELECT DATABASE >> choose test@myserver

The result is:

   387: No connect permission.
   111: ISAM error:  no record found.
kostafey
  • 11
  • 2
  • When you created the database, did you grant access to the users you're trying to connect as? You don't have to grant it explicitly to "informix". Depending on the mode of the database, you may need to 'GRANT CONNECT TO PUBLIC' (or to specific users rather than everyone — GRANT CONNECT TO mary). If you created a MODE ANSI database, this probably necessary. If you created a regular logged database, then you probably don't need to do it. Check who has access by running 'SELECT * FROM "informix".sysusers' to see who does have access. You can use RESOURCE or DBA instead of CONNECT if you want.. – Jonathan Leffler Apr 20 '20 at 03:35
  • Connection refused would indicate that your database is not listening on port 8202 on localhost, because Java cannot even connect to that port. – Mark Rotteveel Apr 20 '20 at 08:04
  • "Connection refused" from java should lead to a SQL error -908, meaning JDBC cannot connect to the port. This is before JDBC would authenticate the user. Are you running the JDBC program from the same machine where the database engine resides? Firewalls and forgetting to change 'localhost' to the actual host name are common issues when ran from another machine. – Brian Hughes Apr 20 '20 at 13:12
  • @JonathanLeffler, `GRANT CONNECT TO PUBLIC` -> `Permission granted.` `GRANT CONNECT TO mary` -> `Permission granted.` `SELECT * FROM "informix".sysusers` -> `Informix, mary, public` (can't format output as-is). But the result is the same: `jdbc:informix-sqli://localhost:8202/test:INFORMIXSERVER=myserver;user=mary;password=joebar;` -> `(Connection refused) java.net.PlainSocketImpl.socketConnect (PlainSocketImpl.java:-2)` – kostafey Apr 20 '20 at 19:55
  • @MarkRotteveel `cat $INFORMIXDIR/etc/sqlhosts` -> `myserver onsoctcp localhost port_alias`. `cat /etc/services` -> `... port_alias 8202/tcp`. `netstat -tulpn | grep 8202` -> `tcp6 0 0 ::1:8202 :::* LISTEN` – kostafey Apr 20 '20 at 20:00
  • @BrianHughes Both Informix database and JVM running on localhost. – kostafey Apr 20 '20 at 20:02
  • Are you sure the informix JDBC drivers supports IPv6? have you tried using the IPv6 address instead of localhost. With the current error, your question is technically a duplicate of [java.net.ConnectException: Connection refused](https://stackoverflow.com/questions/6876266/java-net-connectexception-connection-refused) – Mark Rotteveel Apr 21 '20 at 07:22
  • I think if you are listening on an IPV6 port you need to check if localhost maps to it. Or use ::1 as the host instead of 'localhost'. My guess is the server is listening on the IPv6 network interface and not on the IPV4 localhost. – Brian Hughes Apr 21 '20 at 21:39
  • 1
    @BrianHughes, thank you! Using ::1 instead of localhost is a solution. – kostafey Apr 26 '20 at 20:40

0 Answers0