I'm working within Eclipse. I've added a TomEE server which starts up fine but there seems to be a problem creating a MySQL DataSource.
I defined the following DataSource in TomEE 1.7.2:
<Resource id="jdbc/WCMDS" type="javax.sql.DataSource">
jdbcDriver com.mysql.jdbc.Driver
jdbcUrl jdbc:mysql://localhost:3306/wcm?useUnicode=yes&characterEncoding=utf8&autoReconnect=true
jtaManaged false
password pass
userName user
InitialSize 50
MaxActive 100
MaxIdle 3
</Resource>
In my bean, I retrieve the DataSource
@PostConstruct
public void postConstruct() {
InitialContext context = new InitialContext();
String dataSourceName="java:/comp/env/"+getDatasourceJndiName();
DataSource dataSource = (DataSource) context.lookup(dataSourceName);
DATASOURCE = dataSource;
In bean method that executes a query, I use retrieved DataSource to obtain a connection.
Connection connection = DATASOURCE.getConnection();
Then I build a PreparedStatement
connection.prepareStatement("select * from myTableName");
While preparing the statement, I run into javax.el.ELException: org.hsqldb.HsqlException: user lacks privilege or object not found: myTableName
=============================================================
Please note, this isn't a problem on the database side. When I replace the jndi lookup with manually created datasource, things work fine.
MysqlDataSource datasource = new MysqlDataSource();
datasource.setURL("jdbc:mysql://localhost:3306/wcm?useUnicode=yes&characterEncoding=utf8&autoReconnect=true");
datasource.setUser("user");
datasource.setPassword("pass");
DATASOURCE=datasource;
=============================================================
So the error I'm getting must have something to do with the datasource being managed by TomEE. Why would a connection from such datasource prevent me from creating statements?