Connection with a remote database using java swing application
I am working with a swing application and the initial part of the application is "user authentication" ..for that module i want to authenticate(verify) the user but the problem is that my database is remo开发者_Python百科tly located with different port(not 1521). everytime i try to connect through some easy and simple jdbc,a well designed exception occures to decorate my console something like this
"SEVERE: null java.sql.SQLException: Io exception: The Network Adapter could not establish the connection at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146) at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:255) at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387) at oracle.jdbc.driver.PhysicalConnection.(PhysicalConnection.java:414)"
The Programmers who have worked with swings specially when they made a tool for some webservices might have fallen into the same category..please give it a look and thought.
using simple JDBC
you can connect to remote oracle DB.
LDAP is essentially a big Map allowing you to look things up. You don't use that to talk to an Oracle database, but a JDBC-driver.
You will need one that corresponds to your Oracle database, and you have two options:
- thin: This one is in pure Java and you need to use the IP-number or DNS-name of the database server.
- thick: This one calls the same libraries as SQLPLUS so you can use the same database names as you can in SQLPLUS.
Also note that the Swing application needs to be able to actually reach the database across the network for this to work. Usually Oracle runs on port 1521. This frequently means firewall rules for any non-trivial setup.
This is clearly a network problem, meaning that you cannot access the database through the network or maybe the provided url is invalid. Also, make sure that you use something like this:
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);
connection = DriverManager.getConnection(url, username, password);
The Light Directory Access Protocol is used for authenticating users into the application, not for connecting to the database.
I am also having this same problem. When connecting from Swing application framework alone, this error is coming. I am able to connect to the database from PLSQL Developer. I am also able to connect to db using another java desktop application, which is not based on "SwingAppliation Framework". I am trying to connect to database from Task classes, and it fails. In The other application which works, I am using normal java class. In both the application I am using Hibernate.
精彩评论