Tuesday, 15 February 2011

JavaEE/JDBC/Maven/Glassfish - cannot find symbol error.. "variable con of type java.sql.Connection" -



JavaEE/JDBC/Maven/Glassfish - cannot find symbol error.. "variable con of type java.sql.Connection" -

so far i've done next steps:

1.start glassfish in command line.

2.went glassfish url set connection pool name (cis4278) proprerties.

3.set database name (cis4278) , set username, password , other properties.

4.created jdbc connection resource (called jdbc/arivera) , connected cis4278 pool.

5.created persistence.xml file in web-inf folder of project

<?xml version="1.0" encoding="utf-8"?> <persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="cis4278" transaction-type="jta"> <provider>org.eclipse.persistence.jpa.persistenceprovider</provider> <jta-data-source>jdbc/arivera</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/> <property name="javax.persistence.schema-generation.create-source" value="metadata"/> <property name="javax.persistence.schema-generation.drop-source" value="metadata"/> <property name="javax.persistence.jdbc.user" value="app"/> <property name="javax.persistence.jdbc.password" value="app"/> </properties> </persistence-unit> </persistence>

now i'm trying create table in database create through glassfish using java file created:

package edu.ndnu.arivera; import java.sql.*; import javax.sql.*; import javax.annotation.resource; public class dbcreate{ @resource(name="jdbc/arivera") datasource ds; public void connectandquerydb(string username, string password) { connection con = ds.getconnection(); statement stmt = con.createstatement(); stmt.executequery("create table voter (firstname varchar(30),lastname varchar(30), address varchar(30), city varchar(30), state varchar(30), zip varchar(30), phone varchar(30), affil varchar(30))"); con.close(); } }

however when seek compile in commandline error:

[error] /home/student/contestedcounty/src/main/java/edu/ndnu/arivera/dbcreate.java:[13,21] cannot find symbol [error] symbol: method createstatement() [error] location: variable con of type java.sql.connection

in addition, error i'm not sure if i'm going right way create table.

i'm not using netbeans there's no easy ui create tables. i'm thinking compiling java file rest of code create table when phone call method in 1 of other java-ee/xthml files.

if thought process wrong, should create table? thanks.

cannot find symbol: method createstatement() of type java.sql.connection

java method names (and other identifiers) case-sensitive.

it should

con.createstatement(); // lower-case "c"

sql maven java-ee jdbc glassfish

No comments:

Post a Comment