Socket write error with activejdbc - java

I have a pretty simple commandline app that runs inside of eclipse that connects to an Oracle 12 database and issues a pretty simple query. I'm getting the following exception:
Exception in thread "main" org.javalite.activejdbc.InitException: Failed to connect to JDBC URL: jdbc:oracle:thin:#oratest2a.emspic.org:1521:workstst
at org.javalite.activejdbc.DB.open(DB.java:93)
at org.javalite.activejdbc.Base.open(Base.java:64)
at org.emspic.works.RegistrationUtil.doMain(RegistrationUtil.java:135)
at org.emspic.works.RegistrationUtil.main(RegistrationUtil.java:75)
Caused by: java.sql.SQLRecoverableException: IO Error: Connection reset by peer: socket write error
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:752)
at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:666)
Code throwing the exception is basically this:
// use properties to open the datasource for work
System.out.println("Opening database connection.");
logger.info("Opening database");
String dbDriver = dbProps.get("dbDriver");
String dbURL = dbProps.get("dbURL");
String username = dbProps.get("username");
String password = dbProps.get("password");
Base.open(dbDriver, dbURL, username, password);
logger.info("Database successfully opened.");
Everything I've googled indicates the problem is a "network issue"...except that on this same machine, I am currently connected to the very table I'm trying to open via TOAD...and I also am running a jboss as server connecting to that very same database...so there is no way it is a network problem.
I'm at a total loss.
Java1.8, ojdbc7.jar, all running on a Microsoft Surface Pro 3..., Oracle version is 12.0.2 running remotely.

Your exception has nothing to do with AcitveJDBC. There is a problem with your Oracle configuration. I bet you will get the same exception if you try just JDBC with the same parameters. When/if you fix your issue with JDBC, ActiveJDBC will work just fine.

Related

Getting adal4j/AuthenticationException while connecting to Azure SQL from Google Dataproc Cluster

Please hear me out.
I am able to successfully write to Azure SQL server table using Apache Spark connector in Dataproc cluster. But then while testing I found sometime that the SQL server database in not available and because of this the write operation fails.
So, I decided to add an exception logic to check if the database is available or not using the following code before writing to Azure DB,
var connection: Connection = null
val url = "jdbc:sqlserver://***.database.windows.net:1433;databaseName=some_db;encrypt=true;trustServerCertificate=true;authentication=ActiveDirectoryPassword"
val user = "xxxx"
val password = ******
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver")
connection = DriverManager.getConnection(url, user, password)
log.info(s"Successfully established connection on attempt: "+attempts)
return
}
This code works fine in my local machine. But while running the same in Dataproc I am getting the below error,
Exception in thread "main" java.lang.NoClassDefFoundError: com/microsoft/aad/adal4j/AuthenticationException
I already went though this similar issue discussed in SO. But it's bit different for me as the Apache Spark connector to write to SQL server is working fine. I just want to have the code DriverManager.getConnection(url, user, password) work to test the connection before my write.

Cannot connect to SQL Server from Java

I have a problem when I try to connect to SQL Server with Java. I have the next error:
The connection to the host DESKTOP-C0SCI39, named instance failed. Error: "java.net.SocketTimeoutException: Receive timed out". Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434. For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
My firewall is off and I don't know what is wrong(mssql-jdbc-8.4.1.jre14 is included). This is my Java code:
String url = "jdbc:sqlserver://DESKTOP-C0SCI39\\;databaseName=students";
try {
Connection connection = DriverManager.getConnection(url);
System.out.println("Connected to MS SQL");
} catch (SQLException throwables) {
System.out.println("Error!");
throwables.printStackTrace();
}
Try this solution, I have ran into similar problems in the past and have found that these help.
Check that the JDBC Driver is imported in the project. (Preferred - 5.1.48)
Check that your SQL Server is up and running (Check if SQL Service is running)
Check if you entered your connection string properly
eg: private String URL = "jdbc:mysql://localhost:3306/dbName"; //database url
Try adding a useSSL=false to the end of your connection string dbName?useSSL=false
Open your server with a server management software such as SQL Server Management Studio to see if your SQL Server is working as it should
Your database is not running where you think it is running. Verify the port and location of the server and try again.

Unable to connect to a Oracle db from Linux machine in java

I have registered a Linux machine as runner in my gitlab and tried to execute my scripts there.
While executing I got an error for database connection
Issue : java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
When I connect from my local machine (Windows 7 & 10) it is working fine.
Attempts:
Tried to connect using jtds but I'm getting some other unknown issue.
Checked few other answers and they have provided that it could be because of firewall enabled but since we did not have full access to that db server , I could not disable and check.(Could this be the issue?)
My Connection code :
ConURL = "jdbc:oracle:thin:#" + ConstructSQLConnectionURL(host,sid,port);
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(ConURL, dbUserName, dbPassword);
I am stuck with this issue and blocked from executing pipeline.
Can anyone let me know what could be the possible reason for this and help me with this?
Thanks in advance
It appears to be a network connectivity issue. I'd start with local firewalls on each system. Can you ping the database from the client? If not, look for network routing or firewall blockers. Also look at host-based firewalls, or confirm with the DBA whether there is something like valid node checking in place to limit database clients.

Unable to connect Java application to SQL Server database

I am trying to write a Java desktop app that can connect to my database made with Microsoft SQL Server Manager to allow me to view and update it. But, I am having trouble getting the connection to work. I've read through a bunch of tutorials and threads here on Stack Exchange of similar problems, and I'm not sure what I'm doing wrong.
The server is called "SQLEXPRESS" using Windows authentication. I downloaded the JDBC driver found here: https://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=11774 installed it in NetBeans by going to "Services-Databases(right click)-New Connection-Add", but I also added it as a library in my project.
When I try this code, I get the exception that the TCP/IP connection failed either because the server isn't running or port 1433 is locked:
try{
String
URL="jdbc:sqlserver://sqlexpress:1433;DatabaseName=GreenhouseManagement";
Connection conn = DriverManager.getConnection(URL,"","");
System.out.println("connected");
}catch(Exception e){
System.out.println("Oops\n"+e);
}
What do I need to change to fix this?
You might need to reconfigure your connection string into this format.
jdbc:microsoft:sqlserver://HOST:1433;DatabaseName=DATABASE
HOST in this case is most likely to be "localhost" since you are connecting on a local machine.
DATABASE will be the name of your database
Reference: http://alvinalexander.com/java/jdbc-connection-string-mysql-postgresql-sqlserver

Unable to get SQL Server connection object

I wrote a simple code to connect to SQL Server database and to does a simple select statement, this code runs successfully on my local machine over VPN but when I deploy the same code in the servers, then my code is stopping at getting the DB connection object.
It is not even throwing any timeout exception, so I thought of a port issue and checked using telnet which is successful. Can anyone please suggest why this might happen? I am able to get connection object of the same DB from my local machine over VPN.
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = props.getProperty("DBURI");
Connection conn=null;
System.out.println(connectionUrl.trim());
conn = DriverManager.getConnection(connectionUrl.trim());
Problem with the sqljdbc jar file , Used any 32 bit one , After replacing the jar , everything worked fine. Thanks

Categories

Resources