Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI connection

 
veesam sridhar
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I configured JNDI connection and I am able access the datasource from jsp

I wrote a normal class for getting connection in src directoy of my application:
-----------------

import javax.naming.*;
import javax.sql.*;
import java.sql.*;


public class Connection{

public static Connection getConnection()
{
try {
Context ctx=new InitialContext() ;
if (ctx==null)
throw new Exception("No Context is there");
DataSorce ds=(DataSorce) ctx.lookup("java:comp/env/jdbc/mysqldb");
if(ds!=null)
{
Connection conn=ds.getConnection();
return conn;
}
else
throw new Exception("Could not get connection");
} catch(Exception e) {
e.prinStackTrace();
}

}




}


-----------------

I am trying to compile that class.

But it is govoing the following error:
---------------------------------------------------------
Connection.java:4: cannot find symbol
symbol : class DataSorce
location: package javax.sql
import javax.sql.DataSorce;
^
Connection.java:17: cannot find symbol
symbol : class DataSorce
location: class Connection
DataSorce ds=(DataSorce) ctx.lookup("java:comp/env/jdbc/mysqldb");
^
Connection.java:17: cannot find symbol
symbol : class DataSorce
location: class Connection
DataSorce ds=(DataSorce) ctx.lookup("java:comp/env/jdbc/mysqldb");
^
Connection.java:26: cannot find symbol
symbol : method prinStackTrace()
location: class java.lang.Exception
e.prinStackTrace();
^
4 errors

--------------------------------------------------



I am not able to find out why it is saying Cann ot find DataSource symbol.

Please help me.


Thank you,
Sridhar.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34973
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sridhar,
You have two typos in there.

DataSorce --> DataSource
e.prinStackTrace --> e.printStackTrace
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic