java - Can not find symbol DataSource -
i cant run next code suppose missing dependency (jar file), when run code shows next error
severe: java.lang.runtimeexception: uncompilable source code - cannot find symbol symbol: class datasource location : class com.myproject.model
import java.sql.connection; import java.sql.preparedstatement; import java.sql.resultset; import java.sql.sqlexception; import java.sql.statement; import javax.naming.context; import javax.naming.initialcontext; import sun.jdbc.odbc.ee.datasource; //and import javax.sql.datasource both not work public class authmodel { public connection dbconnection(){ connection con = null; seek { context ctx = new initialcontext(); cant find symbol error >> datasource ds = new (datasource)ctx.lookup("mydatabase"); con = ds.getconnection("root", ""); con.setautocommit(false); .....
dependencies
<dependencies> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-core</artifactid> <version>2.3.8</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-tiles-plugin</artifactid> <version>2.3.8</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-convention-plugin</artifactid> <version>2.3.8</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts2-dojo-plugin</artifactid> <version>2.3.8</version> </dependency> <dependency> <groupid>org.apache.struts</groupid> <artifactid>struts-taglib</artifactid> <version>1.3.10</version> </dependency> <dependency> <groupid>jdbc</groupid> <artifactid>jdbc-stdext</artifactid> <version>2.0</version> <type>pom</type> </dependency> <dependency> <groupid>javax.sql</groupid> <artifactid>jdbc-stdext</artifactid> <version>2.0</version> <type>pom</type> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <compilerarguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerarguments> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-war-plugin</artifactid> <version>2.1.1</version> <configuration> <failonmissingwebxml>false</failonmissingwebxml> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <version>2.1</version> <executions> <execution> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputdirectory>${endorsed.dir}</outputdirectory> <silent>true</silent> <artifactitems> <artifactitem> <groupid>javax</groupid> <artifactid>javaee-endorsed-api</artifactid> <version>6.0</version> <type>jar</type> </artifactitem> </artifactitems> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
i'm speculating here looks classpath issue. see you're importing javax.sql
. need import javax.sql.*
or javax.sql.datasource
? also, please ensure have necessary jar.
also, if have 2 different packages same class, there possibility of class conflicts. have tried renaming variables along bundle path.. aka
public final static string my_database = "mydatabase" ... javax.sql.datasource datasource = new (javax.sql.datasource)context.lookup(my_database);
also, 1 side note, not utilize variables con, ctx , authmodel , utilize fullnames aka authentionmodel, xproject, connection, context, datasource , on.
java sql maven jdbc datasource
No comments:
Post a Comment