wood burning stoves 2.0*
The moose likes Websphere and the fly likes Hi,I have a problem in database connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Hi,I have a problem in database connection" Watch "Hi,I have a problem in database connection" New topic
Author

Hi,I have a problem in database connection

Lakshmi siri
Ranch Hand

Joined: Feb 06, 2004
Posts: 44
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
Vinod Bijlani
Ranch Hand

Joined: Mar 06, 2002
Posts: 133
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

Joined: Feb 06, 2004
Posts: 44
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.
 
subject: Hi,I have a problem in database connection
 
Similar Threads
Servlet connection with Jdbc
Oracle Connectivity with thin drivers
oracle Conenctivity using Thin Drivers
Oracle Connectivity with thin drivers !!
Classes12.zip Thin Drivers