Win a copy of High Performance Python for Data Analytics this week in the Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

JNDI connection

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 40400
821
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sridhar,
You have two typos in there.

DataSorce --> DataSource
e.prinStackTrace --> e.printStackTrace
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic