I am trying to make a connection to a CA Datacom database from a Spring Java application. I am new to both Spring/Java and Datacom. After doing some searching I have come across a few resources (very few). In these I had and idea of what the connection should be. This is what I have in my application.yml so far for my datasource stuff, and I am not sure if it is right or not (doesn't seem to be):
spring:
application:
name: MyBatchApplication
datasource:
url: jdbc:datacom://hostname:hostport/ServerName=xxxx,ApplicationID=xxxx,UserID=xxxx,Password=xxxx
driver-class-name: ca.datacom.jdbc.DatacomJdbcDriver
I do have a jar file that is the driver for Datacom, and am importing that into my project with my build.gradle. I have code in my main project that tests the connection and it works that way. So that code is:
public static void main(String[] args) {
String url = "jdbc:datacom://hostname:hostport/ServerName=xxxx,ApplicationID=xxxx,UserID=xxxx,Password=xxxx";
try {
Connection conn = DriverManager.getConnection(url);
if (conn != null) {
System.out.println("We have a connection");
conn.close();
} else {
System.out.println("There is no connection");
}
} catch (SQLException e) {
System.out.println(e.getLocalizedMessage());
}
SpringApplication.run(MyBatchApplication.class, args);
}
So the top part there works great. I get the We have a connection message. However, once the bottom part runs with the Spring application I get an error saying:
IO error sending or receiving native data: ca.datacom.db.DBIOException: MAINFRAME SERVER ERROR: REQUESTED SERVER NOT AVAILABLE
So I am at a loss. I know the server is available, and I know my credentials are correct since it works in the Java, but the Spring connection for some reason doesn't work.
Related
I am trying to connect to SQL Server using my credentials.
The data I am provided is to connect is the following:
Server: Ccddb294\oss_prod
Database: OSS_DW
Code:
public static void main(String arg[]) throws ClassNotFoundException, SQLException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String dbURL = "jdbc:sqlserver://ccddb294.corp.corpcom.com:1433;databaseName=OSS_DW;integratedSecurity=true";
Connection conn = DriverManager.getConnection(dbURL,"corp\\e21290","Anjali#1234");
if (conn != null) {
System.out.println("Connected");
}
}
I am not sure where to give oss_prod in server name. When I try to connect, I get this error:
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Integrated authentication failed. ClientConnectionId:26ddec01-2e7e-46c3-8165-4f3646da5e7c
Can someone validate if the dbURL which I created is correct as per specification or do I need to add odd_prod - but if so, where? (Note: The dll file is correctly placed in bin and i am able to connect to server at least but not able to authenticate only)
After lots of hit and trials.
Following is correct db URL:
"jdbc:sqlserver://ccddb294.corp.corpcom.com:1433;
instanceName=oss_prod;
databaseName=OSS_DW;
integratedSecurity=true;
domain=corp;
authenticationscheme=NTLM;
user=e21290;
password=Anjali#1234";
I have a very interesting issue and I'm not having any luck finding the source of the issue.
My company recently updated to a newer version of Java and the old ODBC connection method for connecting to an MS Access DB is no longer working. So I'm in the process of updating to a new method.
I found Ucanaccess which seems to be a good alternative as the connection is read only.
So following the getting started I updated the details in the code for Ucanaccess.
This is where i ran into a interesting problem.
I've added the following to my project
ucanaccess-3.0.4.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
hsqldb.jar
jackcess-2.1.3.jar
and update the connection creation code to the following
System.out.println("Establisting Connection.....");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://Z:\\Database\\test.accdb");
System.out.println("Connection Establisted.....");
The first database I used was password protected so I thought that might be causing the issue so I switched to a new database. The second database was on a shared drive so i mapped the location to the above. Even with those two changes I'm still getting the same issue.
The problem is that each time i run the DriverManager.getConnection line the code it never reaches the System.out.println("Connection Establisted....."); line. There is no error messages and the program is still running so no crash. The strange thing is that if i put an invalid path in i do get to that line. Though i do get an error saying the file doesn't exist.
I've had no luck tracking down a solution to this issue.
I think could be problems with the URL connection. It works for me:
public class ConnectionUcanaccess {
static
{
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
System.out.println("driver loaded");
} catch (ClassNotFoundException e) {
System.out.println("the class driver can't be loaded");
}
}
static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:ucanaccess:///Users/shared/Desktop/database.accdb");
}
public static void main(String[] args){
try {
Connection con = ConnectionUcanaccess.getConnection();
System.out.println("Connected: " + !con.isClosed());
} catch (SQLException e) {
System.out.println("Error:" + e.getMessage());
}
}
}
I'm currently working on a small project which involves writing information from a CSV file to a MySQL database.
I'm using netbeans and have added the MySql JDBC JAR file to the project which is needed for the connection. When running the code below the program does not move on past the driver manager.getConnection statement. I am lost for ideas at this stage. My username and password is definitely correct and I am certain I have the URL right. No errors are returned, the project seems to just get stuck.
I am using a database that is hosted by blacknight hosting services, would this make a difference?
public static void writeToDatabase()
{
try {
String url = "jdbc:mysql://172.16.2.10:57983/db1320939_sa63898_main";
Connection conn = DriverManager.getConnection(url,"u1320939_kd","svpgalway21");
conn.close();
System.out.println("It worked!");
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
Try catching Throwable instead of Exception. Maybe you're getting an Error while you connect to the DB and you wouldn't notice it. Also include a finally clause with a trace.
I am working on a dynamic webapp on eclipse and is trying to access a remote MySQL database. I made sure that all the information is correct. However I can't seem to connect to it. Here's my getConnection method:
public static Connection getConnection() throws SQLException {
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://50.56.81.42:3306/GUEST_BOOK";
String user = "username";
String password = "password";
conn = DriverManager.getConnection(url, user, password);
System.out.println("CONNECTED");
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch(InstantiationException e){
e.printStackTrace();
}catch(IllegalAccessException e){
e.printStackTrace();
}
return conn;
}
I am trying to see what the error is but because this is a web app, I can't see that system.out.println anywhere, so it's kind of hard for me to debug with this. Any suggestions on how to debug?
Is your MySQL server accessible from out of the server? I am asking because it is possible to disable external connection for MySQL server, more info is here.
Your credentials are OK (at least its format).
Otherwise, you create Class.forName("com.mysql.jdbc.Driver").newInstance(); but you don't assign it to conn variable.
In web applications, System.out prints to the server's logs file. If you are using tomcat, see logs directory inside tomcat's base directory.
If you are still struggling to see the System out in logs, try to test the class from standalone java class, you will clearly see what the problem is.
So I have a MySQL database set up on a Debian server and it works fine from a phpMyAdmin client. I'm currently working on a project to write a Java server that would be able to use the MySQL database that is already on this server through a JDBC connection. I've looked at many tutorials and documentations but all of them seem to just explain how to do client-side code, but I have yet to figure out how to even successfully open a JDBC connection to the server. As far as I am concerned, I believe that program has the drivers properly set up because it's not crashing anymore (I simply direct the Java Build Path of my program to the Connector/J provided by MySQL). As far as my program goes, this is what it looks like...
import java.sql.*;
public class JDBCTest {
public static void main(String[] args) {
System.out.println("Started!");
try {
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
System.out.println("Driver registered. Connecting...");
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/", "root", "password");
System.out.println("Connected!");
conn.close();
} catch (SQLException e) {
System.out.println("Error!");
e.printStackTrace();
}
}
}
This is what's printed...
Started!
Driver registered. Connecting...
It's as if the DriverManager.getConnection(String) just freezes there. I'm sure this is a problem with the server because when I intentionally misspell localhost, or an IP address, the program crashes within 20 seconds. This just hangs there forever.
Sorry about this wall of text, but my final question is if anyone has any information what I should do or install on the server to get this to work? Thank you so much!
Try following:
public class MySqlDemo {
public static void main(String [] args) {
java.sql.Connection conn = null;
System.out.println("SQL Test");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = java.sql.DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test?user=root&password=");
}
catch (Exception e) {
System.out.println(e);
System.exit(0);
}
System.out.println("Connection established");
}
You have to provide the name of the Schema to which you are connecting. Usually, the port is also added.
This is a sample connection string:
jdbc:mysql://repos.insttech.washington.edu:3306/johndoe?user=johndoe&password=jddb
3306 is the port and the first instance of johndoe is the name of the Schema. The second instance of johndoe is the username.
It could be that the Connector/J library is trying to use a named pipe to connect to the MySQL server rather than using TCP/IP and for some reason the named pipe isn't available. Try specifying a port number.
You may also want to try turning on some logging in Connector/J's configuration as described here.
Try putting port number and schema there
Try logging into database using some SQL client, may be SQL console
Try other drivers, may be some newer or perhaps older