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