aspose file tools*
The moose likes JDBC and the fly likes  SQL Error: 1049, SQLState: 42000 - please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark " SQL Error: 1049, SQLState: 42000 - please help" Watch " SQL Error: 1049, SQLState: 42000 - please help" New topic
Author

SQL Error: 1049, SQLState: 42000 - please help

Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Please see the error that I'm getting in red below:

This is the problem that I really need help on:
"...
594 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
937 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1049, SQLState: 42000
937 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Unknown database 'localhost.test.mysql.db'
937 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'localhost.test.mysql.db'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

..."

This is my hibernate.cfg.xml:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:mysql://localhost/Original</property>
<property name="connection.username">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password">root</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<!-- thread is the short name for
org.hibernate.context.ThreadLocalSessionContext
and let Hibernate bind the session automatically to the thread
-->
<property name="current_session_context_class">thread</property>
<!-- this will show us all sql statements -->
<property name="hibernate.show_sql">true</property>

<!-- mapping files -->
<mapping resource="UserAccount.hbm.xml" />

</session-factory>
</hibernate-configuration>
------------------------------------------------------------------------

This is my jdbc.properties:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/localhost.test.mysql.db
jdbc.username=root
jdbc.password=root
hibernat.dialect=org.hibernate.dialect.MySQLDialect

---------------------------------------------------------------------------
Additional Trace showing the error:

Mar 5, 2010 1:08:22 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing log4j from [C:\Eclipse\eclipse\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Original\WEB-INF\log4j.properties]
log4j:ERROR setFile(null,true) call failed.
java.io.FileNotFoundException: \WebContent\WEB-INF\CoupansAppServer.log (The system cannot find the path specified)

at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.log4j.FileAppender.setFile(FileAppender.java:272)
at org.apache.log4j.RollingFileAppender.setFile(RollingFileAppender.java:156)
at org.apache.log4j.FileAppender.activateOptions(FileAppender.java:151)
.....
Mar 5, 2010 1:08:22 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
2010-03-05 13:08:22,278 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
2010-03-05 13:08:22,371 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Fri Mar 05 13:08:22 EST 2010]; root of context hierarchy
2010-03-05 13:08:22,512 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
2010-03-05 13:08:22,824 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - Loading properties file from ServletContext resource [/WEB-INF/jdbc.properties]
2010-03-05 13:08:22,855 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d62270: defining beans [propertyConfigurer,dataSource,sessionFactory,HibernateUserAccount,UserCoupanDao,transactionManager]; root of factory hierarchy
2010-03-05 13:08:22,886 INFO [org.springframework.jdbc.datasource.DriverManagerDataSource] - Loaded JDBC driver: com.mysql.jdbc.Driver
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
405 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: BzIncCouponsApp.DaoPojo.UserAccount -> useraccount
2010-03-05 13:08:23,433 INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - Building new Hibernate SessionFactory
594 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
937 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1049, SQLState: 42000
937 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Unknown database 'localhost.test.mysql.db'
937 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown database 'localhost.test.mysql.db'
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)


--------------------------------------------------------------------------

Any ideas will be greatly appreciated.

Many Thanks...Mimi
Jinglong Wang
Greenhorn

Joined: Mar 05, 2010
Posts: 12
hi,
i think the exception is not important..

the important is the database connection...

the error said:Unknown database 'localhost.test.mysql.db'

the database name is invaild..

check your database name and correct it..

then try again..
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121

Thank you very much for your response.

Please see my 2 pictures attached here.

My database 'localhost.test.mysql..db' was opened successfully with my jdbc driver and same name in Eclipse under Windows/Perferences/Data Managent/Connectivity/Driver Definition/<tab: Properties>.

So, I suppose the database name was good. When you say: "..the database name is invaild..", can you elaborate on it a little please?

I am trying to solve this problem almost the whole day but to no avail. Any other ideas that I should try? I'd appreciate any ideas and help.


[Thumbnail for dbConnectedWithSameName.png]

[Thumbnail for mysqldb.png]

Jinglong Wang
Greenhorn

Joined: Mar 05, 2010
Posts: 12
i'm try to create a new datebase with name "localhost.test.mysql.db"
but EMS(SQLManager 2007 for mysql) said:inadmissible char"." in name "localhost.test.mysql.db"
i dont know you that how to create it.
i dont think hibernate can parse the datebase name.
change your datebase without "."
try again..

glad to help you..

excuse of my english..
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Hi,

Thank you very much for the idea. I deleted the old db and created a new one with no '.' in the file name. This time it wouldn't connect.

Below: 1st is the console log from Eclipse, 2nd picture was from the command line (mysqld works but not mysql - same error). The last picture was from MySQL Workbench when I tried to connect. Please see RED lines on the trace.

2010-03-05 17:52:50,364 INFO [org.springframework.web.context.ContextLoader] - Root WebApplicationContext: initialization started
Mar 5, 2010 5:52:50 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
2010-03-05 17:52:50,458 INFO [org.springframework.web.context.support.XmlWebApplicationContext] - Refreshing Root WebApplicationContext: startup date [Fri Mar 05 17:52:50 EST 2010]; root of context hierarchy
2010-03-05 17:52:50,614 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
2010-03-05 17:52:50,942 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - Loading properties file from ServletContext resource [/WEB-INF/jdbc.properties]
2010-03-05 17:52:50,973 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1d62270: defining beans [propertyConfigurer,dataSource,sessionFactory,HibernateUserAccount,UserCoupanDao,transactionManager]; root of factory hierarchy
2010-03-05 17:52:50,988 INFO [org.springframework.jdbc.datasource.DriverManagerDataSource] - Loaded JDBC driver: com.mysql.jdbc.Driver
31 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
31 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
47 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
421 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: BzIncCouponsApp.DaoPojo.UserAccount -> useraccount
2010-03-05 17:52:51,582 INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - Building new Hibernate SessionFactory
610 [main] INFO org.hibernate.connection.ConnectionProviderFactory - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
2903 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01
2903 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Communications link failure


The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
2903 [main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
...


Any ideas will be greatly appreciated.




[Thumbnail for mysqldb.png]

[Thumbnail for mysqld.png]

Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Problem finally solved. Thanks.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Mimi Tam wrote:Problem finally solved. Thanks.
Can you share the solution?

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
hem kumar
Ranch Hand

Joined: Sep 05, 2005
Posts: 97
yes, i have also never seen this type of naming of database in mysql. Can you share the solution to your problem please?


.....For Every Problem There Is a Solution.....
Regards, Hem
Mimi Tam
Ranch Hand

Joined: Mar 05, 2010
Posts: 121
Yes, this worked for me

Try turning on your MySQL service manually. I started it (from the Services dialog) by hand it (it was on Automatic). And, it connected!

Good Luck, my dear friends
Jinglong Wang
Greenhorn

Joined: Mar 05, 2010
Posts: 12
er....i had been thinking is it restart can solve..
but i am afraid it's wrong ,so ... keep silent..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL Error: 1049, SQLState: 42000 - please help
 
Similar Threads
SQLGrammarException
Problems with hibernate and mysql?
hbm file version working but annotation not
24 Hour Format In HQL - 00:00:00 returned as 24:00:00 using HQL
Error running the application