wood burning stoves 2.0*
The moose likes JDBC and the fly likes Problems Connecting to a database through a Swing Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problems Connecting to a database through a Swing Application" Watch "Problems Connecting to a database through a Swing Application" New topic
Author

Problems Connecting to a database through a Swing Application

Shantanu Rathore
Greenhorn

Joined: Feb 12, 2010
Posts: 6
Hi
I have just started learning Swing.

What I am trying to do:
Creating an application which will retrieve some data from a Oracle Database.

What I have done so far:
I am trying to connect to the Database first and I wish to proceed further once the connection is established.

PROBLEM: I am getting the following error when I run the application: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

Code:- (this is just the code for the Button Click. Filename:DesktopApplicationView.java )

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
String s=null;
String ret_msg;
String messg=null;
Object env_name=jComboBox1_EnvNames.getSelectedItem();
s=env_name.toString();
jTextField2.setText(s);
Connection conn;//This is the point from where I feel the real problem begins

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thin:@10.*.*.*:1523:oron","user","pass");

ret_msg="Connection to the DB Established";


}
catch (ClassNotFoundException c)
{
ret_msg=c.toString();
System.out.println(ret_msg);
}
catch (SQLException sq_ex)
{
ret_msg=sq_ex.toString();
System.out.println(ret_msg);
}


jTextField3.setText(ret_msg); //I am expecting it to return: 'Connection to the DB Established' but instead it returns the error message.

}


Some Facts:-
*The database I am trying to connect to is huge. Is that a problem? I tried connecting to the database through a standalone program and it worked.
*I tried to make a separate class to do all the database related work and call it through this class but it throws the same error.
*I am new to Swing...just started yesterday...so anything which makes you say

<removed inappropriate content>






[jc: removed four letter words from the post. Please mind your language]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

This is really about JDBC, not swing. So I'm going to move this to the JDBC forum.


GenRocket - Experts at Building Test Data
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

Hi Shantanu,

Please use code tags. Makes it easier to read your code.
You can edit your post by clicking on the Edit icon at its right top.


OCUP UML fundamental and ITIL foundation
youtube channel
Shantanu Rathore
Greenhorn

Joined: Feb 12, 2010
Posts: 6
Re-posting with code tags:-

Hi
I have just started learning Swing.

What I am trying to do: Creating an application which will retrieve some data from a Oracle Database.

What I have done so far: I am trying to connect to the Database first and I wish to proceed further once the connection is established.

PROBLEM: I am getting the following error when I run the application: java.sql.SQLException: Io exception: The Network Adapter could not establish the connection

Code:- (this is just the code for the Button Click. FilenameesktopApplicationView.java )




Some Facts:-
*The database I am trying to connect to is huge. Is that a problem? I tried connecting to the database through a standalone program and it worked.
*I tried to make a separate class to do all the database related work and call it through this class but it throws the same error.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problems Connecting to a database through a Swing Application