I just installed MySql Community Server, and I have a MySql Connection called mysqlserver. I created a schema called library, with some tables. Everything seems fine with the database, but when I try to generate bean classes with hibernate reverse engineering from Eclipse, I am getting this error:
org.hibernate.exception.SQLGrammarException: Getting database metadata
Getting database metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mysqlserver'
Unknown database 'mysqlserver'
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'mysqlserver'
Unknown database 'mysqlserver'
The interesting thing is that my tables are fetching, so I can see them from Eclipse, but the error is still here while trying to generate classes.
My guess was that the problem is with my url, but how are tables fetched then:
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">mypassword</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/library</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
I do not get it how can mysqlserver be unknown database, when I specified that my database is library. I lost hours while trying to google it, and still nothing. Can anyone help me with this please?
Now, I am experiencing a new problem - I cannot start the server any more. I stopped it yesterday, and tried to start it now, it just won't start any more. The server log says:
Could not open error log file: [Errno 2] No such file or directory: 'SAMS-PC.err'
2014-02-06 13:10:32 - Status check of service 'MySQL56' returned stopped
2014-02-06 13:10:32 - Starting server...
2014-02-06 13:10:34 - Status check of service 'MySQL56' returned stopped
2014-02-06 13:10:34 - Server start done.
2014-02-06 13:10:34 - Status check of service 'MySQL56' returned stopped
Your jdbc string should be
hibernate.connection.url = jdbc:mysql://localhost:3306/mysqlserver
hibernate.default_schema = library
you schema is library, you database name mysqlserver.
I resolved the last issue, with starting the server from console. I don't know why MySql workbench didn't start it, but I will be satisfied with this solution for now. Later the server stopped working again, and so on... So, I concluded that I do not like MySql very much.
I solved the original problem, too. The problem was something unrelated to hibernate configuration - I forgot to create a .reveng.xml file. Embarrassing...
Anyway, thank you for willingness to help.
Related
I'm new to Sybase database and trying to connect to Sybase using Java JDBC connection and sajdbc4.jar, but getting an error:
java.sql.SQLException: [Sybase][JDBC Driver][SQL Anywhere]Database server not found
Here is my connection string:
jdbc:sqlanywhere:uid=user;pwd=xxxx;eng=xx_sql;database=dummy;links=tcpip(host=xx.xx.xx.xx)
Firstly ensure that you point the database file to the SQL Anywhere Server and restart the server.
Secondly analyze your database logs, check if you can trace the connectivity with SQL PLUS or any other database connectivity tools.
If you are able to solve it, then that's fine or else I suspect that the issue to be related to this issue on SO here
As per this question, please make the following changes and I guess that the issue should be resolved
jdbc:sqlanywhere:Server=yourservername;uid=user;pwd=xxxx;port=2638;eng=xx_sql;database=dummy;links=tcpip(port=2638)
It is mandatory to mention the use of TCP/IP protocol to yourJDBC driver through the connection string above!
Hope this helps!
I am trying to complete this tutorial:
https://netbeans.org/kb/docs/javaee/ecommerce/connect-db.html
Part of it is setting up a database and trying to establish a connection using datasource and connection pooling.
I did everything that is in the tutorial but when i try to run my code i get the following error:
javax.servlet.jsp.JspException: Unable to get connection, DataSource invalid: "java.sql.SQLException: No suitable driver found for jdbc/affablebean"
Here is the code that throws it:
<sql:query var = "result" dataSource = "jdbc/affablebean">
SELECT * FROM category, product
WHERE category.id = product.category_id
</sql:query>
I tried to connect to the database without using connection pooling and datasource and it worked like a charm.
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver registered");
}
catch (ClassNotFoundException ex) {
Logger.getLogger(SqlService.class.getName()).log(Level.SEVERE, null, ex);
}
That means that the driver is in the right lib folder in the glassfish directory so the problem must be somewhere else.
The tutorial has a troubleshooting section where they describe that if i get this kind of error "No suitable driver found for jdbc/affablebean" that means that i do not have resource reference in my web.xml. Well... I DO HAVE ONE and here it is:
<resource-ref>
<description>Connects to database for AffableBean application</description>
<res-ref-name>jdbc/affablebean</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
I have been trying to solve this problem 16 hours a day for more than two day but still NO luck.
Do you guys have some idea what is wrong?
I browsed all the google and stackoverflow and found similar problems but the solution they give is "Make sure the mysql driver is in the right folder on the server".
Why do i connect to the database without dataSource object but can not connect with one?
So i found the solution to the exact same problem I was having.
So it appears that the issue was within web.xml not containing a reference to the datasource.
Simply add,
<resource-ref>
<description>AffableBean DataSource</description>
<res-ref-name>jdbc/affablebean</res-ref-name>
<res-type>javax.sql.ConnectionPoolDataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
to your web.xml file and save and run file(right click inside the file and press "Run File").
Afterwards you should see the database tab pop up in your browser of choice.
I had same error,
the problem is on when you set resource-type:
Resource Type: javax.sql.ConnectionPoolDataSource
try using:
Resource Type:=javax.sql.DataSource
thats strange in tutorial text is (the problem):
Click Next. In Step 5, Add Connection Pool Properties, specify the
following details: Datasource Classname:
com.mysql.jdbc.jdbc2.optional.MysqlDataSource Resource Type:
javax.sql.ConnectionPoolDataSource Description: (Optional) Connects to
the affablebean database
but on screenshot is correct.
I had several issues with this
https://netbeans.org/kb/docs/javaee/ecommerce/connect-db.html
part of ecommerce tutorial.
First problem (no suitable driver fourd) appeared due to improper jdbc resource creation -
i used 'new file \ glassfish \ jdbc connection pool'
instead of 'new file \ glassfish \ jdbc resource'.
Redoing this step registered driver correctly and created pool
(was indicated in glassfish servel log that mysql driver did register on server instance).
After that i couldn't get data via testDataSource.jsp - error was org.apache.derby.client.am.SqlException: Table/View 'CATEGORY' does not exist.
I couldn't figure out why org.apache.derby.client was even mentioned and
after some lookup found discussion on netbeans forum:
https://forums.netbeans.org/ntopic61746.html
This part of discussion was solution for my case:
try to change in step setup file sun-resources.xml or glassfish-resources.xml
Setting up a JDBC data source and connection pool
at step 6 -> change Resource Type to javax.sql.ConnectionPoolDataSource
and change in step setup file web.xml
Referencing the data source from the application
at step 4 -> change Resource Type to javax.sql.ConnectionPoolDataSource
p.s. i'm using netbeans 8.0.2, glassfish 4.1 and jdk1.7.0_21.
There was no javax.sql.ConnectionPoolDataSource option in Netbeans'
interface for 'edit resource reference \ resource type' combobox for web.xml.
So i put this value there manually.
After a very tiresome research, having checked servers tomcat, wildfly,and Jboss, none seemed to work,I had problem with registering new datasource with glassfish, adding new jdbc connectionpool would throw java.lang.runtimeexception, the workaround for this issue was to reconfigure DerbyPool under jdbcconnection pools in admin console and feeding it with required Datasource Classname, url,username,and password to point it the database on mysql server.and it did work.
I think you did not add Mysql JDBC Driver in your project libraries.
Add manually Mysql JDBC Driver in your project libraries and try again.
I think it will work.
I have the exactly problem, and even thru Netbeans IDE, the DB connection test is fine while in Glassfish 4, it is not working, try all possible like include lib in project, put here and there. Finally the problem is fixed by remove Glassfish and install Glassfish 3.1.2.2, the project files is exactly same and working fine. Guess this is a bug or specail setting may needed in Glassfish 4.
I had the same issue. The last 4 hours I was looking for a solution and it was so easy for me...
Make sure the "Status" in JDBC Resource (at Glassfish Admin Console) is Enabled (checkbox is checked) :-(
Same problem here. I spent hours with this, tried some of the solutions offered here, and only one got me a step further: changing the Resource Type from "javax.sql.ConnectionPoolDataSource" to "javax.sql.DataSource.
I immediately stumbled upon the next problem: the table "category" didn't exist. It actually does exist.
I gave up on glassfish (this was my first time trying to use glassfish) and went back to Tomcat. Succes! So I decided it might be helpful to point people to another possible solution that worked for me.
For those who are interested in the Tomcat solution, visit this page http://tomcat.apache.org/tomcat-8.0-doc/jndi-datasource-examples-howto.html#MySQL_DBCP_Example. Very clear explanation with an example. And don't forget to add the JSTL library to your project.
Good luck.
I am using a brand new developing pc and need to test a personal application that runs on a local GlassFish server 3.1.2 and should connect with a local SQL database called 'funkOneDB' (my IDE is NetBeans 7.2.1). But I can't get the GlassFish server to connect with the database, and the problem seems to be related to the (place of the) SQL driver in the GlassFish Server's directories (more problem specifics in a few lines).
I am fairly certain I correctly set up the related JDBC Resource and Connection Pool on the GlassFish Server (as I mimic a set-up already existing and working properly on another developing pc).
The Resource specifics are:
jndi name: jdbc/FunkResource
pool name: FunkPool
The (most important) Pool specifics are:
pool name: FunkPool
resource type: javax.sql.Datasource
datasource classname: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
additional properties correspond to the specifics in the XML GlassFish-resources of the application (username, password, url, etc.; no problems there)
I first placed the necessary SQL driver in the GlassFish Server's directories, i.e. the file mysql-connector-java-5.1.18-bin.jar at ..\GlassFish3\GlassFish\domains\domain1\lib\ext.
Yet, when I perform a ping test from the JDBC Pool 'FunkPool' at the GlassFish server, I get the following error:
Ping Connection Pool failed for FunkPool. WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped Please check the server.log for more details.
In the server.log I only find the following extra logging exception and failure info:
(i) Exception while creating an unpooled [test] connection for pool [ FunkPool ], WEB9031: WebappClassLoader unable to load resource [com.mysql.jdbc.SQLError], because it has not yet been started, or was already stopped
(ii) RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=FunkPool}'
Note however, that when I ping the database funkOneDB from my IDE NetBeans via jdbc:mysql://localhost:33066/funkOneDB, it's succesful. As already mentioned, the credentials and other data I use for this IDE-based ping are the same data I use in the JDBC Connection Pool.
I searched for the problem also on stackoverflow for some. And I did find some people talking about it, like
Glassfisch MySQL ping ERROR (no answer by anybody), or
Struggling to create MySQL Connection Pool on Glassfish (tried that solution, i.e. putting the SQL driver one level up in ..\GlassFish3\GlassFish\domains\domain1\lib\, but this creates other errors, even after restarting the Glassfish server), or
GlassFish not loading connector
(even tried this solution, no succes).
Can somebody help me solve this problem? Many thanks in advance!
With kind regards,
Heinz
Place the mysql driver in the lib folder of your project. Then do a clean-and-build. It's also helpful to have netbeans communicate directly with your database. This will allow you to view the database structure and the contents of your database right from your IDE. For help integrating MySQL with netbeans, look here: netbeans.org/kb/docs/ide/mysql.html
My friend, i had this same exception:
RestResponse.getResponse() gives FAILURE. endpoint = 'http://localhost:4848/management/domain/resources/ping-connection-pool.json'; attrs = '{id=FunkPool}'
The cause of my error was that, i put wrong credentials. Check your credentials in your client DB App (SQL Developer, for example).
I had the same problem with SQL server and Netbeans. To resolve it, i put the sqljdbc.jar in the java direcory "Java\jdk1.8.0_121\lib directory" and it works :)
I've just spebnt 10 hours on this bug.
I developed a web application on a test server, with an Oracle10g test database, using Hibernate 3.6.0 for ORM. Everything works fine on the test server.
When I moved this web application to the production server and the production Oracle10g database, I encountered a strange issue: the server times out when I try to run an update query in Hibernate (I receive an Internal Server Error).
These are the last lines logged by Tomcat:
2011-05-03 15:45:09,083 DEBUG (org.hibernate.pretty.Printer:113) - fsmodule.model.Organization{organizationid=65, ogroup=fsmodule.model.Ogroup#5, nature=fsmodule.model.Nature#2, name=Norway, factsheets=<uninitialized>}
2011-05-03 15:45:09,083 DEBUG (org.hibernate.pretty.Printer:110) - more......
2011-05-03 15:45:09,091 DEBUG (org.hibernate.jdbc.AbstractBatcher:410) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2011-05-03 15:45:09,092 DEBUG (org.hibernate.SQL:111) - update RESPONSE set FACTSHEET_FACTSHEETID=?, QUESTION_QUESTIONID=?, TEXT=? where RESPONSEID=?
2011-05-03 15:45:09,099 DEBUG (org.hibernate.jdbc.AbstractBatcher:66) - Executing batch size: 1
... and that's all! No error outputed, nothing else. The select queries work very well, but I have the same issue with the insert queries.
Moreover, my users told me that the application worked fine at first, and then it stopped working correctly (I did not change the web application whatsoever in the meantime).
Also note that if I connect directly to the database with the same credentials than the ones used by the hibernate.cfg.xml file, I can flawlessly update the rows.
What could be going wrong?
Thank you all for your always-precious help.
Have you configured c3p0 connection pool? http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool
I've setup up a Security Realm in Glassfish to authenticate against an Active Directory server. The configuration of the realm is as follows:
Class Name: com.sun.enterprise.security.auth.realm.ldap.LDAPRealm
JAAS context: ldapRealm
Directory: ldap://172.16.76.10:389/
Base DN: dc=smallbusiness,dc=local
search-filter: (&(objectClass=user)(sAMAccountName=%s))
group-search-filter: (&(objectClass=group)(member=%d))
search-bind-dn: cN=Administrator,CN=Users,dc=smallbusiness,dc=local
search-bind-password: abcd1234!
The realm is functional and I can log-in, but when ever I log in I get the following error in the log:
SEC1106: Error during LDAP search with filter [(&(objectClass=group)(member=CN=Administrator,CN=Users,dc=smallbusiness,dc=local))].
SEC1000: Caught exception.
javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name 'dc=smallbusiness,dc=local'
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2820)
....
....
ldaplm.searcherror
While searching for a solution I found that it was recommended to add java.naming.referral=follow to the properties of the realm. However, after I add this it takes 20 minutes for GlassFish to authenticate against Active Directory. I suspect it is a DNS problem on the Active Directory server. The Active Directory server is a vanilla Windows Server 2003 setup in a Virtual Machine.
Any help/recommendation is highly appreciated!
This is the configuration I use in my domain.xml file, it might be of some interrest to you :
<auth-realm classname="com.sun.enterprise.security.auth.realm.ldap.LDAPRealm" name="ldapRealm">
<property name="search-bind-password" value="Demodemo01"/>
<property name="search-bind-dn" value="Administrator"/>
<property name="search-filter" value="(&(objectClass=user)(sAMAccountName=%s)(!(userAccountControl:1.2.840.113556.1.4.803:=2)))"/>
<property name="group-search-filter" value="(&(objectClass=group)(member=%d))"/>
<property name="jaas-context" value="ldapRealm"/>
<property name="base-dn" value="CN=Users,DC=saierp,DC=net"/>
<property name="directory" value="ldap://192.168.1.38:389"/>
</auth-realm>
Specially, make sure to add the userAccountControl to your filter, otherwise, disabled accounts in AD will be allowed to connect.
This was maddening trying to solve this... Glassfish 3.0.1 trying to connect with Windows, and getting the above error.
I'm not a Windows or LDAP whiz at all... but finally found this:
http://forum.springsource.org/showthread.php?t=87673
And the very last line is the key: use the "Global Catalog Port" - instead of 389, it is 3268 by default. And the exception disappears.
Why?
Who cares?
(well, ok, I'm going to read about it now.)
Hopefully, you've resolved this, but just in case:
I used 'objectCategory' in place of 'objectClass' as I read the former are indexed, hence faster.
I had to add this property:
property name="assign-groups" value="Domain Users"
where "Domain Users" is the group in AD that all of our users are placed into. This must match the value in sun-web.xml for security-role-mapping.
Later, I was able to create a specific group for this application and make the appropriate changes.