JDBC无法解析为类型 [英] JDBC cannot be resolved to a type
问题描述
我正在尝试在我的类定义中使用 @JDBC
注释,但Eclipse表示 JDBC无法解析为类型
。为什么是这样?
我使用MySQL作为数据库引擎,我添加了 mysql-connector-java
到 WEB-INF / lib
并将其添加到项目的Build Path。
没有选项当我点击同一行代码上的红色方块上的X灯泡时,导入任何东西 - 只需创建注释JDBC
。
import java.util.List;
import javax.sql.DataSource;
@JDBC
public class MyClass {
...
}
此注释在不 / api /rel =nofollow> Java EE ,也不在 JDBC 。
鉴于MySQL + JDBC + Java EE + Eclipse的组合,您可能会遵循本教程和copypasting代码,而不阅读文本。它提到以下内容:
还要注意,我们定义了一个新的注释@JDBC。这允许我们将正确的存储库注入到Servlet中,如下所示:
package com.bookstore;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType。*;
import static java.lang.annotation.RetentionPolicy。*;
import javax.inject.Qualifier;
@Qualifier @Retention(RUNTIME)@Target({TYPE,METHOD,FIELD,PARAMETER})
public @interface JDBC {
}
所以,你必须自己创建 。 >
I'm trying to use the @JDBC
annotation in my class definition as below, but Eclipse says JDBC cannot be resolved to a type
. Why is that so?
I'm using MySQL as database engine and I've added the mysql-connector-java
to WEB-INF/lib
and added it to the Build Path of the project.
There's no option to import anything when I click on the lighbulb with an X on red square on the same line of code - just the Create annotation JDBC
.
import java.util.List;
import javax.sql.DataSource;
@JDBC
public class MyClass {
...
}
This annotation does not exist in Java EE nor in JDBC at all.
Given the combination MySQL + JDBC + Java EE + Eclipse, you were likely following this tutorial and copypasting code without reading the text. It mentions the following:
Also notice that we defined a new annotation called @JDBC. This allows us to inject the right repository into the Servlets as follows:
package com.bookstore; import java.lang.annotation.Retention; import java.lang.annotation.Target; import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.*; import javax.inject.Qualifier; @Qualifier @Retention(RUNTIME) @Target({TYPE, METHOD, FIELD, PARAMETER}) public @interface JDBC { }
So, you've got to create it yourself.
这篇关于JDBC无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!