Reputation: 121
so far I've done the following steps:
1.Start Glassfish in the command line.
2.Went to GlassFish URL to set up the Connection Pool Name (CIS4278) its proprerties.
3.Set up the Database Name (CIS4278) and set up username, password and other properties.
4.Created a JDBC Connection Resource (called it jdbc/arivera) and connected it with my CIS4278 pool.
5.Created a persistence.xml file in WEB-INF folder of my 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 to create a table in the database I create through Glassfish using this Java file I 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 I try to compile in the commandline I get this 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, to this error I'm not sure if I'm even going about the right way to create a Table.
I'm not using Netbeans so there's no easy UI to simply create the tables. I'm thinking that compiling this java file with the rest of my code would create the Table when I call the method in one of my other Java-EE/XTHML files.
If my thought process is wrong, what should I do to properly create a table? Thanks.
Upvotes: 0
Views: 460
Reputation: 262734
cannot find symbol: method CreateStatement() of type java.sql.Connection
Java method names (and all other identifiers) are case-sensitive.
It should be
con.createStatement(); // lower-case "c"
Upvotes: 3