Fan Yi peak 1 minute ago
Enter a questionnaire to win a good book, and publish the results of the reader survey.
This is my hibernate. cfg. xml file.
<? 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>
<! -- Generated by myeclipse hibernate tools. -->
<Hibernate-configuration>
<Session-factory>
<Property name = "dialect">
Org. hibernate. dialect. sqlserverdialect
</Property>
<Property name = "hibernate. Connection. url"> JDBC: sqlserver: // 127.0.0.1: 1433; databasename = "shopping"; </property>
<Property name = "hibernate. Connection. username"> SA </property>
<Property name = "hibernate. Connection. Password"> SA </property>
<Property name = "hibernate. Connection. driver_class">
Com. Microsoft. sqlserver. JDBC. sqlserverdriver
</Property>
<Property name = "hibernate. show_ SQL"> true </property>
<Mapping Resource = "model. HBM. xml"/>
</Session-factory>
</Hibernate-configuration>
An error is reported after the program is run:
Log4j: warn no appenders cocould be found for logger (Org. hibernate. cfg. Environment ).
Log4j: Warn please initialize the log4j system properly.
Exception in thread "Main" org. hibernate. Exception. sqlgrammarexception: cannot open connection
At org. hibernate. Exception. sqlstateconverter. Convert (sqlstateconverter. Java: 90)
At org. hibernate. Exception. jdbcexceptionhelper. Convert (jdbcexceptionhelper. Java: 66)
At org. hibernate. Exception. jdbcexceptionhelper. Convert (jdbcexceptionhelper. Java: 52)
At org. hibernate. JDBC. connectionmanager. openconnection (connectionmanager. Java: 449)
At org. hibernate. JDBC. connectionmanager. getconnection (connectionmanager. Java: 167)
At org. hibernate. JDBC. jdbccontext. Connection (jdbccontext. Java: 142)
At org. hibernate. transaction. jdbctransaction. Begin (jdbctransaction. Java: 85)
At org. hibernate. impl. sessionimpl. begintransaction (sessionimpl. Java: 1354)
At com. examp. shoppingonline. hibernate. dboperate. Save (dboperate. Java: 211)
At com. examp. shoppingonline. Test. testadduser. Main (testadduser. Java: 17)
Caused by: COM. Microsoft. sqlserver. JDBC. sqlserverexception: the database requested to log on to '"shopping"' cannot be opened. Logon Failed.
At com. Microsoft. sqlserver. JDBC. sqlserverexception. makefromdatabaseerror (sqlserverexception. Java: 197)
At com. Microsoft. sqlserver. JDBC. tdstokenhandler. Oneof (tdsparser. Java: 246)
At com. Microsoft. sqlserver. JDBC. tdsparser. parse (tdsparser. Java: 83)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. sendlogon (sqlserverconnection. Java: 2529)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. Logon (sqlserverconnection. Java: 1905)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. Access $000 (sqlserverconnection. Java: 41)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection $ logoncommand. doexecute (sqlserverconnection. Java: 1893)
At com.microsoft.sqlserver.jdbc.tdscommand.exe cute (iobuffer. Java: 4575)
At com.microsoft.sqlserver.jdbc.sqlserverconnection.exe cutecommand (sqlserverconnection. Java: 1400)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. connecthelper (sqlserverconnection. Java: 1045)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. login (sqlserverconnection. Java: 817)
At com. Microsoft. sqlserver. JDBC. sqlserverconnection. Connect (sqlserverconnection. Java: 700)
At com. Microsoft. sqlserver. JDBC. sqlserverdriver. Connect (sqlserverdriver. Java: 842)
At java. SQL. drivermanager. getconnection (drivermanager. Java: 582)
At java. SQL. drivermanager. getconnection (drivermanager. Java: 154)
At org. hibernate. Connection. drivermanagerconnectionprovider. getconnection (drivermanagerconnectionprovider. Java: 133)
At org. hibernate. JDBC. connectionmanager. openconnection (connectionmanager. Java: 446)
... 6 more
I am grateful to anyone who can help solve this problem!