Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems Connecting to a database through a Swing Application

 
Shantanu Rathore
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is really about JDBC, not swing. So I'm going to move this to the JDBC forum.
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Shantanu Rathore
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic