I did a java project with netbeans using derby. The project runs fine in the IDE, but when i build it and run from the .jar file without starting server from the netbeans, it displays:
"java.net.ConnectException : Error connecting to server localhost on port 1527
with message Connection refused: connect."
How can i connect to the database on my client`s machine without netbeans on it?
You need to know the IP of your DB server, as localhost or 127.0.0.1 refers to the DB installed on local machine, and if you run the app on client's machine it is pretty sure, that this DB is not there locally. You need to specify the exact IP address, if multiple clients should connect to the same DB.
If you just need a DB per app, then you can use Embedded Derby, that starts and stops with your application, so you don't really need external server (very good solution in case when this is the only app that use this DB):
public String driver = "org.apache.derby.jdbc.EmbeddedDriver";
...
Class.forName(driver).newInstance();
Get an Embedded Connection
public String protocol = "jdbc:derby:";
...
conn = DriverManager.getConnection(protocol + "derbyDB;create=true", props);
That embedded connection URL, fully constructed, looks like this:
jdbc:derby:derbyDB;create=true
Related
JT400 - The JDBC connection is working fine when connecting to a IBMi machine from windows machine.
DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
String sysname = "xxx.xxx.xx.xxx";
String xref = "IBMISQLLIB";
String url = "jdbc:as400://" + sysname + ";translate binary=true;prompt=false;naming=sql;libraries=" + xref;
Connection connection = DriverManager.getConnection(url, "USERNAME", "PASSWORD");
print("Connection created successfully");
But fails to create the connection by using the same code - when running the code on the same IBMi machine (by a runnable jar on 'QSH Command Entry'), ERROR:
java.sql.SQLException: The application requester cannot establish the
connection. (A remote host refused an attempted connect operation.
(Connection refused)) at
com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:887)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:610)
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:568)
at
com.ibm.as400.access.AS400JDBCConnectionImpl.setProperties(AS400JDBCConnectionImpl.java:3522)
at
com.ibm.as400.access.AS400JDBCDriver.prepareConnection(AS400JDBCDriver.java:1430) at
com.ibm.as400.access.AS400JDBCDriver.initializeConnection(AS400JDBCDriver.java:1280)
at
com.ibm.as400.access.AS400JDBCDriver.connect(AS400JDBCDriver.java:403)
at java.sql.DriverManager.getConnection(DriverManager.java:675) at
java.sql.DriverManager.getConnection(DriverManager.java:258)
Any idea what is going wrong now ??
because this was working some days back
Same code is working on other IBMi servers
Some more details about the IBMi machine are:
No access right issue for the username used in connection profile
No firewall is setup on IBMi machine
TCP/IP configuration is verified as explained - Configuring TCP/IP on IBM i
Is the database host server active? Use WRKACTJOB to see if jobs name QZDASOINIT are running.
If not, try starting the host server with the command STRHOSTSVR *DATABASE.
If you're running your jar file from QSH, you need to make sure that multi-threading is allowed. That could possibly gum things up.
The same code should work just fine if it works on the PC unless you are using a different version of the jt400.jar file possibly as well.
Try using localhost also instead of a system name.
Or even writing a small Java class to open and close a connection.
The problem was related to default TCP/IP port, which was not listening the JDBC connection request.
And finally the problem got resolved by restarting the IBMi machine.
:)
I am trying to migrate some code from JavaFX to use C# for Windows Forms. In Java, I was using JDBC and could connect just fine programmatically. Nos that I am trying to use C# I am getting this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server).
I am using the same server address and credentials. I'm using System.Data.SqlClient. I've tried a bunch of different combinations but can't get the connection string to work.
String connectionString = "server=[Server URL];database=[Database Name];persist security info=true;user id=[Username];pwd=[Password]";
Here is an example of the mysql connection string:
string connectionString = "datasource= <database ip or domain>; port=<port, usually 3306>;username=<database user>;password=<user's password>;SslMode=none<this is important if you don't use ssl>;database=<your database>";
I think the reason you can't connect is because you haven't specified the SslMode.
I designed a java application using net beans, which connects to a database that is present on port 1527 and retrieves data. I have prepared a executable jar file by using build and compile. After running the jar i am getting the following error.
java.sql.sqlnontransientconnectionexception java.net.connectexception
error connecting to server localhost on port 1527 with message connection refused connect
I have written the following code for connecting to derby database
Class.forName("org.apache.derby.jdbc.ClientDriver");
String host= "jdbc:derby://localhost:1527/database/project.db;create=true";
Connection conn;
String user="user1";
String pass="pass1";
conn = DriverManager.getConnection(host,user,pass);
if (conn!= null) {
JOptionPane.showMessageDialog(null,"Connected to database");
}
Is this error because of un availability of db on server or i have to do anything other than the code?
If i use a local database in my system the application is working fine. That db address i used in the code is given by the person who asks me to develop the application.
I've tryed to create a connection with a Microsoft SQl Server 2008 database through JDBC on Eclipse SDK. I've dowloaded JDBC driver from microsoft and I've installed it, then I've added at my System environment variables CLASSPATH the path of sqljdbc4.jar file. After icluding in the Eclipse project the jar file I've tryed to create the connection using:
String connectionUrl = "jdbc:sqlserver://localhost;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl);
but it doesn't works, and launch me this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: TCP/IP connection
at host localhost, port 1433 failed. Error: "Connection refused:
connect. Verify connection properties and make sure an instance of SQL
Server is running on the host and is accepting TCP/IP connections at
the port. Be sure no firewall blocks connections at the port.
I'm working on a JRE 1.6 so a sqljdbc4 should work, and I've created a working ODBC, so the server is responding, and the error should be in java command or JDBC installation.
Can anyone help me?
At the risk of stating the obvious, this looks to me as if TCP connections haven't been enabled on SQL Server. You have to manually enable them, they don't come enabled by default.
There's an article on MSDN here which explains how to enable TCP protocols for SQL 2005/2008.
Following are the quick trouble shooters:
Try to connect to your server using external front end.
Check if your firewall blocks the connection to the port
Check to see if server is really up.
A Suggestion :
If you are using eclipse , you don't need to add the jar into CLASSPATH variable , you can just add it in library of your project to make it available at runtime
I am trying to connect to MySQL database over a network. I have installed MySQL, and the service is running on the default port. I have also install the SQL connector to the jar file and added java JDK to the server machine. I am able to connect to my local database using the code:
private String dbUrl = "jdbc:mysql://localhost/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";
But when I try and connect to it over the network, with the IP address (eg: 192.168.1.45):
private String dbUrl = "jdbc:mysql://192.168.1.45/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";
I get the connection error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Does anyone know what this issue is? Do I need to add a different address?
I have added the default port with the address but cannot get it to work.
Thanks for any help.
By default, MySQL doesnt allow remote access and only allow local access.
You will have to modify your /etc/mysql/my.cnf config (on Linux) with:
bind-address = 192.168.1.45 // Your Server IP address
# skip-networking // This should be commented .
See the whole procedure here.
Check the my.cnf [mysqld] settings for the parameters port, bind-address, socket, to make sure these aren't causing problems.
Check the files /etc/hosts, /etc/hosts.deny to make sure everything is ok.
Check firewall applications
Check to make sure whatever directory mysqld's sockets are have the appropriate permissions.
Check to make sure that security settings within the mysql database (user table) permit access from your remote host.
Make sure you can telnet OK to localhost 3306, 127.0.0.1 3306, and whatever other IP address your machine is configured to (use ifconfig to find out).
You can test the server setup using the MySQL Workbench or mysql client which will narrow down the problem. It's also sometimes useful to just see if the server's there:
telnet host 3306
It'll tell you the version number of the server and some other binary junk. Enough to know your host is listening.