CCSID error on JDBC Driver Manager java program running on AS400 - java

I'm trying to build a simple java program that reads a record from a table in AS400. The program runs in the same AS400. I am getting the following error:
Caught exception: INTERNAL ERROR: Creation of DB2Driver object for registering with DriverManager failed. -> com.ibm.db2.jdbc.app.DB2JDBCDataException: CCSID value is not valid.
The java code snippet in the AS400 is the following:
try {
Class.forName("com.ibm.db2.jdbc.app.DB2Driver");
connection = DriverManager.getConnection("jdbc:db2:*local", properties);
} catch (Exception e) {
System.out.println("Caught exception: " + e.getMessage());
}
The exception is thrown at the DriverManager.geConnection method.
Any idea on how to solve this?
Thanks in advance!

Related

Issue with Avatax on UAT environment

I am having sandbox account of Avalara(Avatax) and that is working fine on my local system and also on the staging environment. But the same sandbox credentials are not working on the UAT instance.
Error logged: avaTaxConnection java.net.SocketException: Connection reset
This is the code snippet I used :
try {
client = new AvaTaxClient("PriceBook", "1.0", "https://sandbox-
rest.avatax.com/api/v2/utilities/ping", AvaTaxEnvironment.Sandbox).withSecurity(PropertiesFileConfiguration.Avatax_AccountID,
PropertiesFileConfiguration.Avatax_LicenseKey);
PingResultModel ping = client.ping();
if (ping.getAuthenticated()) {
return client;
}
} catch (Exception e) {
LOGGER.error("ERROR in avaTaxConnection " + e);
}
When I am trying to get PingResultModel ping on the basis of the client object getting the exception: avaTaxConnection java.net.SocketException: Connection reset.
I have also checked whether the connection is created or not, but the connection is created successfully. I printed the connection object in logs.

sybase java DB connection issue

I want to create sybase DB connection in java application.
I've added jconn4.jar to my project, but when I'm connecting to DB in code I have exception ClassNotFoundException: com.sybase.jdbc4.jdbc.SybDriver.
My connection:
SqlConnect() {
try {
DriverManager.registerDriver(new com.sybase.jdbc4.jdbc.SybDriver());
} catch (SQLException e) {
System.err.println("SQL exception " + e.getMessage());
}
}
And also
public void connect() {
try {
connection = DriverManager.getConnection("jdbc:sybase:Tds:localhost:5000", "DBA", "sql");
connection.setAutoCommit(false);
} catch (SQLException e) {
}
}
I want to connect to demo PowerBuilder database, with params:
DSN=EAS Demo DB V125;UID=dba;PWD=sql
What I'm doing wrong?
ADDED
Also when I'm trying to create database connection via intelij database work plugin i also have the same error.
Make sure you have respected jars included on your classpath.
The following works for me:
Use Class.forname to load the drivers
Recommended Approach:
Class.forName("sybase.jdbc.sqlanywhere.IDriver")
con = DriverManager.getConnection("jdbc:sqlanywhere:uid=DBA;pwd=sql");
Another way around:
DriverManager.registerDriver((Driver) Class.forName("sybase.jdbc.sqlanywhere.IDriver").newInstance());
con = DriverManager.getConnection("jdbc:sqlanywhere:uid=DBA;pwd=sql");
The following link will help you in installing drivers:
How to connect Sybase database using Java code in NetBeans?
So, the other jdbc type driver resoled my problem - I connected sajdbcX driver and changed connection string:
connection = DriverManager.getConnection("jdbc:sqlanywhere:uid=DBA;pwd=sql");
So, also thanx Mark Rotteveel for advice - I removed driver register code as redurdrant.
And thank all for ideas.

java.awt.Desktop::open() throws error "The system cannot write to the specified device"

I have production code who, for one user, this line of code keeps throwing an error:
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
Log file shows this as the error:
java.io.IOException: Failed to open C:\Users\flast\Desktop\spreadsheet.xls. Error message: The system cannot write to the specified device.
I am unable to reproduce this error so I cannot provide a SSCCE. But, can anyone shed light as to why Desktop::open() would throw this error? Namely, why is it trying to "write" anything? Desktop::open() should only find the associated program and open the file. There's nothing to write.
Noteworthy: I actually catch this error in my code and try Desktop::browse() instead:
Desktop desktop = Desktop.getDesktop();
try {
desktop.open(file);
} catch (IOException e) {
handleError(e);
desktop.browse(file.toURI());
}
but browse() also throws an error:
Failed to open file:/C:/Users/flast/Desktop/spreadsheet.xls. Error message: Access is denied.
So I'm stumped.

Java RMI Client and Server Separate Machines

I want to edit the RMI hello world example to work with client and server on different machines, but i'm stuck with the unmarshalling return error.
If i run client and server in the same project on Netbeans they work fine but when i split them i edited the try statement on the client side to be:
try {
Registry registry = LocateRegistry.getRegistry("localhost");
String[] c = registry.list();
System.out.println(c[0].toString());
Remote lookup = Naming.lookup("HelloServer");
} catch (Exception e) {
System.out.println("HelloClient exception: " + e.getMessage());
}
without Remote lookup = Naming.lookup("HelloServer");, the print command gives "HelloServer" which is correct, but when i create the remote object I'm getting this error:
HelloClient exception: error unmarshalling return; nested exception is:
java.lang.ClassNotFoundException: rmimain.Hello
I've tested the policy and it's working fine, any help would be much appreciated.
Your client doesn't have the rmimain.Hello class on its CLASSPATH.

Java NetBeans JDBC Connection working in Debug, not in Run

I'm building a little internal tool (non-production code) that gets some stuff from our MS SQL DB. I wanted to try out NetBeans 6.9.1 so am using that.
I have this function to connect to the DB, and I have the System DSN for FAND_DEV setup as SQL Native Client.
private static Connection GetConnection() {
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:odbc:FAND_DEV");
} catch (SQLException ex) {
Logger.getLogger(DAL.class.getName()).log(Level.SEVERE, null, ex);
}
return conn;
}
When I step through the code in debug mode everything is working perfectly. I am getting the expected data back from the DB with no problems.
However, when I try to run (Run Main Project in NetBeans) it is throwing an exception on the DB connection. Any help on this would be greatly appreciated.
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Invalid string or buffer length
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6957)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7114)
at sun.jdbc.odbc.JdbcOdbc.SQLGetDataString(JdbcOdbc.java:3907)
at sun.jdbc.odbc.JdbcOdbcResultSet.getDataString(JdbcOdbcResultSet.java:5698)
at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:354)
at sun.jdbc.odbc.JdbcOdbcConnection.buildTypeInfo(JdbcOdbcConnection.java:1503)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:381)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:207)
at gosDbCopy.db.DAL.GetConnection(DAL.java:53)
With MS SQL you should be able to use JDBC instead of using a JDBC-ODBC bridge. The cause could be related to this though. The cause could be because of the type of data that you are returning as well. This seems to give one example of that.

Categories