Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Annotation error

 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to resolve the compilation error. Could you please help?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sunder Ganapathy:
I am unable to resolve the compilation error. Could you please help?


Only if you tell us what the error is.
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
annotation ch09.Resource is missing type
@Resource(name = "jdbc/bookdb") javax.sql.DataSource mydb;
^
src\ch09\AtResource.java:49: cannot find symbol symbol : variable mydb
location: class ch09.AtResource
connection = mydb.getConnection();
^
2 errors
 
Jeff Rummings
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Resource annotation expects two arguments: a String name and a Class type. You're only passing it a string.

The second error is mydb is declared within the init() method, therefore you cannot access it from doPost().
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I add, type=javax.SQL.DataSource, the compiler says identifier expected.
I still find no clue about it.
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you try javax.SQL.DataSource.class?
javax.SQL.DataSource is the name of the class; javax.SQL.DataSource.class returns the Class object for it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic