• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hi,I have a problem in database connection

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Iam practicing JDBC programs in webshere.Iam using Oracle9i as backend.
when i execute this program iam getting error
Exception: Io exception: The Network Adapter could not establish the connection
Exception:null
Program :

import java.sql.*;
public class CustomerListing {
public static void main(String[] args)
{
Connection con=null;
con=connect();
Statement stmt=null;
ResultSet rs=null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery("Select empno,ename,depno,mgrno from scott.emp a,scott.dept b where a.deptno=b.deptno");

while(rs.next())
{
String s1=rs.getString("EMPNO");
String s2=rs.getString("ENAME");
String s3=rs.getString("DEPTNAME");
String s4=rs.getString("MGRNO");


System.out.println(s1+" " + s2+" "+ s3+" "+ s4);

}
System.out.println("end iof listing");
}
catch(Exception e)
{
System.err.println("Exception:"+e.getMessage());

}
finally{
try
{
if(rs != null) rs.close();
if(stmt!=null)stmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{ }
}
}
protected static Connection connect()
{
String userID="SCOTT";
String password="TIGER";
Connection con=null;
String url="jdbc racle:thin:@bachi:1521 rcl";
try
{


Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection(url,userID,password);

}
catch (Exception e)
{
System.err.println("Exception: "+e.getMessage());
}
return con;
}
}

Error:

Ecception: Io exception: The Network Adapter could not establish the connection
Exception:null
Please give me Advice How to run this program to get ouput.
Localhost--bachi
Thanks for help

- Lakshmi
 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
make sure your able to connect to oracle server from ur websphere box.
was box should be able to communicate to oracle server using the hostname
" bachi "
[ February 08, 2004: Message edited by: Vinod Bijlani ]
 
Lakshmi siri
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanks for your advice.I got it .I have one doubt regarding Sqlserver.
How we can acees the tables from different database in Sql server.
In the same above progrm iam using sql server.Iam getting an exception.
Iam using pubs database which has employee table.
I used "pubs.employee" syntax Then also iam getting same error.

How i can get output?
package simple;
import java.sql.*;
public class Simplesql{
public static void main(String[] args)
{
Connection con=null;
con=connect();
Statement stmt=null;
ResultSet rs=null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery("select emp_id from employee");
while(rs.next())
{
String s1=rs.getString("no");
//String s2=rs.getString("ename");
//String s3=rs.getString("mgr");
// String s4=rs.getString("job");


System.out.println(s1);

}
System.out.println("end iof listing");
}
catch(Exception e)
{
System.err.println("Exception:"+e.getMessage());

}
finally{
try
{
if(rs != null) rs.close();
if(stmt!=null)stmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{ }
}
}
protected static Connection connect()
{
String userID="owner";
String password="owner";
Connection con=null;
String url="jdbc dbc:Lachi";
try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,userID,password);

}
catch (Exception e)
{
System.err.println("Exception: "+e.getMessage());
}
return con;
}
}
package simple;
import java.sql.*;
public class Simplesql{
public static void main(String[] args)
{
Connection con=null;
con=connect();
Statement stmt=null;
ResultSet rs=null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery("select emp_id from employee");
while(rs.next())
{
String s1=rs.getString("no");
//String s2=rs.getString("ename");
//String s3=rs.getString("mgr");
// String s4=rs.getString("job");


System.out.println(s1);

}
System.out.println("end iof listing");
}
catch(Exception e)
{
System.err.println("Exception:"+e.getMessage());

}
finally{
try
{
if(rs != null) rs.close();
if(stmt!=null)stmt.close();
if(con!=null) con.close();
}
catch(SQLException e)
{ }
}
}
protected static Connection connect()
{
String userID="owner";
String password="owner";
Connection con=null;
String url="jdbc dbc:Lachi";
try
{


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection(url,userID,password);

}
catch (Exception e)
{
System.err.println("Exception: "+e.getMessage());
}
return con;
}
}
Iam getting Exception:

Exception:[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'employee'.
Thanks for your help.
Lakshmi
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic