开发者

JDBC MySQL; is supplying the DB name & username/password enough?

When setting up a JDBC connection in a J2EE application, do you need to specify the schema name in addition to the database name?

I have followed this tutorial and have setup a database, and username/password, but I'm coming up against this error when I startup my application. Is it possible that DBUnit is trying to insert the data, before hibernate has initiated and created the schema?

开发者_JAVA百科Caused by: org.dbunit.dataset.NoSuchTableException: Did not find table 'CLIENT' in schema 'null'

My connection details are as follows :

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://127.0.0.1:3306/salestracker"/>
        <property name="username" value="salestracker"/>
        <property name="password" value="salestracker"/>
    </bean>

I have created the database :

[james@nevada sales-tracker]$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.1.42 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| salestracker       |
| test               |
+--------------------+
4 rows in set (0.00 sec)

Do I need to specify something in my hibernate persistence.xml that says to "use" a particular database? I was assuming this would be implied in the JDBC URL


Connect to the database as root and run 'desc client' to see if the table is there (or 'show tables'). If it doesn't find it, then Hibernate isn't auto-creating it. If it does find it, try connecting as salestracker and doing the same thing to see if maybe that user doesn't have the correct permissions. If the table is really there, the next step would be to write a simple Java program to connect and query the table, i.e. remove Hibernate from the equation. Something like:

Class.forName("com.mysql.jdbc.Driver"); 
Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/salestracker", "salestracker", "salestracker"); 
PreparedStatement s = conn.prepareStatement("select count(*) from client"); 
ResultSet rs = s.executeQuery(); 
rs.next(); 
System.out.println(rs.getString(1));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜