The below code creates the datasource sucessfully but there is an exception when test connection is called. But when i restart the server and use the Test connection in console it works.
How to avoid server restart and make the test connection work in the script.
I do have this error after the script is executed and before restart:
J2CA0130I: Data Source [nMINEDB] has Component-managed Authentication Alias [test/nMINEDBUser] but no corresponding J2C Authentication Data Entry is defined in security.xml. This may have undesirable effects.
Code:
#
# Jython Script to create MINE web data-source and JDBC provider.
#
#Import Statements
import os
import re
import sys
# Create JDBC provider for MINE oracle database.
def createMINEJDBCProvider():
server = '/Server:server1'
# Set the Node ID
serverID = AdminConfig.getid(server)
print 'Server ID:' + serverID
#Configuring J2c auth
userAlias='test/nMINEDBUser'
alias = ['alias', userAlias]
userid = ['userId', 'MINEDB']
password = ['password', 'MINEpass']
jaasAttrs = [alias, userid, password]
security = AdminConfig.getid('/Security:/')
print 'security:'+security
j2cUser=AdminConfig.create('JAASAuthData', security, jaasAttrs)
AdminConfig.save()
print 'Creating MINE User sucessfull'
# Test to see if the provider has already been created.
MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:nOracle JDBC Driver/')
if len(MINEJDBCprovider) == 0:
providerName='nOracle JDBC Driver'
print 'creating Oracle JDBC provider on server:'+serverID
print 'JDBC provider Name:'+providerName
MINEJDBCprop1 = ['name', providerName]
MINEJDBCprop2 = ['description','Oracle JDBC Driver for MINE Application']
MINEJDBCprop3 = ['implementationClassName','oracle.jdbc.pool.OracleConnectionPoolDataSource']
MINEJDBCprop4 = ['classpath','C:/jars/ojdbc/ojdbc6.jar']
MINEJDBCprops=[MINEJDBCprop1,MINEJDBCprop2,MINEJDBCprop3,MINEJDBCprop4]
providerID = AdminConfig.create('JDBCProvider', serverID, MINEJDBCprops)
AdminConfig.save()
print 'Creating Oracle JDBC provider on server sucessfull with provider:'+providerID
createMINEDataSource()
else:
print 'oracle provider exists:'+MINEJDBCprovider
def createMINEDataSource():
providerName='nOracle JDBC Driver'
userAlias='test/nMINEDBUser'
MINEJDBCprovider = AdminConfig.getid('/JDBCProvider:nOracle JDBC Driver/')
MINEDataSource = AdminConfig.getid('/JDBCProvider:'+providerName+'/DataSource:MINEDB/')
if len(MINEDataSource) == 0:
# Set the datasource attributes
MINEDSprop1 = ['name', 'nMINEDB']
MINEDSprop2 = ['jndiName', 'jdbc/nMINEdb']
MINEDSprop3 = ['description', 'MINE database']
MINEDSprop4 = ['datasourceHelperClassname', 'com.ibm.websphere.rsadapter.Oracle11gDataStoreHelper']
MINEDSprop5 = ['authDataAlias' , userAlias]
mapConfigprop=["mappingConfigAlias", "DefaultPrincipalMapping"]
mapConfigs=[MINEDSprop5 , mapConfigprop]
mappingConfig=["mapping", mapConfigs]
MINEDSprops = [MINEDSprop1, MINEDSprop2, MINEDSprop3, MINEDSprop4, MINEDSprop5, mappingConfig]
MINEDataSource = AdminConfig.create('DataSource', MINEJDBCprovider, MINEDSprops)
#Set the DB URL
propSet = AdminConfig.create('J2EEResourcePropertySet', MINEDataSource, [])
AdminConfig.create('J2EEResourceProperty', propSet, [["name", "URL"], ["value", "jdbc:oracle:thin:#myserver:1523:MINED2"]])
AdminConfig.save()
print 'Creating MINE JDBC Datasource on server sucessfull with datasource:'+MINEDataSource
#Mapping module not trying right now
#AdminConfig.create('MappingModule', MINEDataSource, mappingConfig)
else:
print 'MINE Datasource already exists in the server:'+MINEDataSource
print 'Testing datasource connection'
print AdminControl.testConnection(MINEDataSource)
try:
print 'start'
createMINEJDBCProvider()
createMINEDataSource()
print 'end'
except:
print "***** Unexpected error while creating JDBC datasource:", sys.exc_info(), " *****"
raise
j2c authentication isn't initialized until the server is recycled.
Related
When trying to issue "SHOW POOLS" or any stats query command on pgbouncer database via JDBC, facing the below exception.
org.postgresql.util.PSQLException: ERROR: unsupported pkt type: 80
at
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2270)
at
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1998)
at
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:406)
at
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:286)
JDBC code:
String connectionUrl = "jdbc:postgresql://"+ipaddress+":"+port+"/"+database;
con = DriverManager.getConnection(connectionUrl, userName, password);
statement = con.createStatement(); statement.executeQuery("SHOW POOLS");
JDBC Driver Version: 42.2.14 ;
PgBouncer Version: 1.14.0 ;
Postgres Version: 11.4;
PS:
Manually able to connect to pgbouncer database and issue all pgbouncer admin commands like SHOW POOLS or SHOW STATS. Just not able to execute the same from JDBC.
JDBC use extended query protocol by default, try simple protocol for such query
String connectionUrl = "jdbc:postgresql://"+ipaddress+":"+port+"/"+database+"?preferQueryMode=simple";
PGBouncer currently supports only the simple protocol - the packet type 80 is for 'Parse', which is the first step in the extended protocol. The message you see in the exception PSQLException actually comes from PGBouncer.
I can login into Postgres using "psql -h localhost -U myuser mydatabase"
But my tuffy config file is like this :
# JDBC connection string; must be PostgreSQL
db_url = jdbc:postgresql://localhost:5432/mydb
# Database username; must be a superuser
db_username = myuser
# The password for db_username
db_password = mypass
# The working directory; Tuffy may write sizable temporary data here
dir_working = /var/postgres/data
But when I run tuffy commands, it show error like this :
Connecting to RDBMS at jdbc:postgresql://localhost:5432/tuffydb Failed
to connect to PostgreSQL! FATAL: password authentication failed for
user "tuffer" Exception in thread "main"
java.lang.NullPointerException at tuffy.db.RDB.query(RDB.java:438) at
tuffy.db.RDB.schemaExists(RDB.java:676) at
tuffy.db.RDB.resetSchema(RDB.java:717) at
tuffy.main.Infer.setUp(Infer.java:77) at
tuffy.main.PartInfer.run(PartInfer.java:18) at
tuffy.main.Main.main(Main.java:29)
I need to be able to identify Type 4 jdbc workload on an IBM mainframe DB2 v10 zos database.
Our mainframe db2 monitor can filter on the following fields
SYSTEM ID
DB2 SUBSYSTEM ID
DATA SHARING GROUP
AUTHORIZATION ID
PLAN NAME
CONNECTION ID
OPERATOR ID
CORRELATION ID
DBRM/PACKAGE ID
BUFFER POOL ID
COLLECTION ID
LOCAL LOCATION
REQUESTING LOCATION
OTHER LOCATION
DATABASE.PAGESET
LOCK RESOURCE
I am guessing many of these values are not available to be changed.
However these items seems likely candidates
CONNECTION ID
CORRELATION ID
REQUESTING LOCATION
OTHER LOCATION
my questions are:-
i). Can the "likely candidates" be set in my java client jdbc code?
ii). How can I set these "likely candidates"?
If i cannot use any of these fields, then I have managed to amend the clientInfo associated with my JDBC connection, as shown in this snippet of jdbc trace
[jcc][Time:2015-12-10-14:39:24.851][Thread:main][Connection#3b6eb2ec] getClientInfo () called
[jcc][Time:2015-12-10-14:39:24.851][Thread:main][Connection#3b6eb2ec] getClientInfo () returned {ClientUser=XXXXXX00, ApplicationName=db2jcc_application, ClientHostname=L0513039, ClientAccountingInformation=JCC04130L0513039 '}
[jcc][SystemMonitor:stop] core: 0.28737999999999997ms | network: 0.0ms | server: 0.0ms
[jcc][SystemMonitor:start]
[jcc][Time:2015-12-10-14:39:24.852][Thread:main][Connection#3b6eb2ec] setClientInfo ({ApplicationName=crsJCC_application}) called
[jcc][SystemMonitor:stop] core: 3.613203ms | network: 0.0ms | server: 0.0ms
[jcc][SystemMonitor:start]
[jcc][Time:2015-12-10-14:39:24.856][Thread:main][Connection#3b6eb2ec] getClientInfo () called
[jcc][Time:2015-12-10-14:39:24.856][Thread:main][Connection#3b6eb2ec] getClientInfo () returned {ClientUser=XXXXXX00, ApplicationName=xxxxxx_application, ClientHostname=L0513039, ClientAccountingInformation=JCC04130L0513039 '}
[jcc][SystemMonitor:stop] core: 0.24718099999999998ms | network: 0.0ms | server: 0.0ms
[jcc][Time:2015-12-10-14:39:24.857][Thread:main][Connection#3b6eb2ec] createStatement () called
[jcc][Time:2015-12-10-14:39:24.863][Thread:main][Connection#3b6eb2ec] createStatement () returned Statement#5ebec15
[jcc
In this case I amended the ApplicationName within ClientInfo, what I would like is that the initial value as customised, e.g. that the initial value WAS'NT "db2jcc_application" but "started out as "xxxxxx_application", is this possible?
Working with the DB2Driver you should be able to set application name like this:
Properties p= new Properties();
p.put("user", "admin");
p.put("password", "secret");
p.put("clientProgramName", "xxxx_application");
Connection conn = DriverManager.getConnection(
"jdbc:db2://localhost:50000/yourdb", props);
If you're using a DB2DataSource, check out this information from IBM:
com.ibm.db2.jcc.DB2DataSource ds =
new com.ibm.db2.jcc.DB2DataSource();
ds.setDriverType(4);
ds.setServerName("localhost");
ds.setPortNumber(50000);
ds.setDatabaseName("sample");
ds.setUser("username");
ds.setPassword("password");
ds.setClientProgramName("My application");
As stated here:
clientProgramName
Specifies an application ID that is fixed for the duration of a physical connection for a client. The value of this property becomes the correlation ID on a DB2 for z/OS server. Database administrators can use this property to correlate work on a DB2 for z/OS server to client applications. The data type of this property is String. The maximum length is 12 bytes. If this value is null, the IBM DB2 Driver for JDBC and SQLJ supplies a value of db2jccthread-name.
I am trying to establish a JDBC connection to Hive so that I can view and create tables and query Hive tables from Eclipse. I used HiveClient sample code: https://cwiki.apache.org/confluence/display/Hive/HiveClient
Then I added all the required jars to the java build path inside eclipse and started Hive Thrift Server. Port 10000 is listening. I am using Cloudera QuickstartVM 4.6.1 and the eclipse that comes with it. Here's the error that I get in the IDE when I try to run the code.
Exception in thread "main" java.sql.SQLException: org.apache.thrift.transport.TTransportException: java.net.SocketException: Connection reset
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:191)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:108)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:103)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at jdbc.Hive.main(Hive.java:24)
When I try connecting to Hive using beeline, I get the same error. However, when I eliminate the host name and port from the !connect command it works with the following error:
beeline> !connect jdbc:hive:// "" ""
scan complete in 4ms
Connecting to jdbc:hive://
14/03/21 18:42:03 WARN conf.HiveConf: DEPRECATED: Configuration property hive.metastore.local no longer has any effect. Make sure to provide a valid value for hive.metastore.uris if you are connecting to a remote metastore.
14/03/21 18:42:03 INFO metastore.HiveMetaStore: 0: Opening raw store with implemenation class:org.apache.hadoop.hive.metastore.ObjectStore
14/03/21 18:42:04 INFO metastore.ObjectStore: ObjectStore, initialize called
14/03/21 18:42:05 INFO DataNucleus.Persistence: Property datanucleus.cache.level2 unknown - will be ignored.
What am I missing here!?
You have 2 options to connect hiveserver using jdbc
Option 1 : Hiveserver2
You are trying to connect hiveserver2, hiveserver version in cloudera manager is hivesever2, which is more secure than hiveserver. JDBC code you are using is hiveserver,Use the following code snippet for hiveserver2
Class.forName("org.apache.hive.jdbc.HiveDriver");
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "hive", "");
Statement stmt = con.createStatement();
String tableName = "testHiveDriverTable";
stmt.execute("drop table if exists " + tableName);
stmt.execute("create table " + tableName + " (key int, value string)");
String sql = "show tables '" + tableName + "'";
If you look at the connection string, can see the hiveserver version 2(jdbc:hive2://localhost:10000/default", "", ""), second and third arguments are username and password, by default keep it empty string "".
For executing this program add hiveserver2 specific libraries.
Instead of writing your own programs for checking hiveserver2 jdbc connection, beeline hive client can be used as follows
> [testuser02#Abcd-Host1 ~]$ beeline
> beeline> !connect jdbc:hive2://Abcd-Host1:10000/default "" "" ""
>
> 0: jdbc:hive2://Abcd-Host1:10000/default> show tables;
+------------+
| tab_name |
+------------+
| sample_07 |
| sample_08 |
| test1 |
+------------+
3 rows selected (0.334 seconds)
Options 2: Hiveserver1
If you want to make use of your existing code(code for hiveserver1), which you are having https://cwiki.apache.org/confluence/display/Hive/HiveClient. You got to start a new hiveserver in your userspace in another port. Use the following command to start a hiveserver in a given port
nohup hive --service hiveserver -p 10001 &
Now change the port number to 10001 in jdbc connection and run it.
I am using Oracle database. I've written a small JDBC connection program in Java but I am facing an issue with the listener.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class JdbcConnection {
public static void main(String[] args) throws SQLException,ClassNotFoundException {
String url = "jdbc:oracle:thin:#localhost:1521:orcl";
String user = "system";
String password = "password";
Connection connection = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
connection = DriverManager.getConnection(url, user, password);
if(connection!=null){
System.out.println("Success in connnection");
} else {
System.out.println("failure in connection ");
}
}
}
I am getting the following exception:
C:\Users\Administrator\Desktop>java JdbcConnection
Exception in thread "main" java.sql.SQLException: Listener refused the connectio
n with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:261)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:
441)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtensio
n.java:35)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at JdbcConnection.main(JdbcConnection.java:18)
This is the output of lsnrctl status
LSNRCTL for 64-bit Windows: Version 12.1.0.1.0 - Production on 16-JUN-2015 13:43
:41
Copyright (c) 1991, 2013, Oracle. All rights reserved.
Welcome to LSNRCTL, type "help" for information.
LSNRCTL> status
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 12.1.0.1.0 - Produ
ction
Start Date 16-JUN-2015 12:02:52
Uptime 0 days 1 hr. 40 min. 52 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\app\orauser\product\12.1.0\dbhome_1\network\admin\l
istener.ora
Listener Log File C:\app\orauser\diag\tnslsnr\hydwemvm\listener\alert\lo
g.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hydwemvm)(PORT=1521)))
Services Summary...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
The command completed successfully
If you know your oracle database SID, then use
jdbc:oracle:thin:#localhost:1521:orcl
otherwise use below in case you have service name
jdbc:oracle:thin:#localhost:1521/orcl
Also, make sure service name with the name ORCL should be up and running. If still doesn't work, then you need to restart your machine and try again above.
Still, not working ? Then, try following :
Login with SYSTEM user and register LOCAL_LISTENER by running below SQLs.
alter system set local_listener = '(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))' scope = both;
alter system register;
How to check oracle SID and service name :
SELECT sys_context('USERENV', 'SID') FROM DUAL; -- It will return your oracle database SID
SELECT sys_context('USERENV', 'SERVICE_NAME') FROM DUAL; -- It will return your oracle database service name
If you want to know the default SID of your database use this query in sqlplus:
SELECT sys_context('USERENV', 'SID') FROM DUAL;
Use this value in the JDBC URL instead of "orcl".
Can you use the below URL?
Note the difference, this is to use the SERVICENAME instead of a SID.
jdbc:oracle:thin:#localhost:1521/orclservice
I am facing the same problem.
Try removing the LAN cable or disconnect your net connectivity and
restart the services of Listener and run the code.
It worked for me.