2014-01-25 53 views
0

我是从JDBC豆类配置

http://www.mkyong.com/spring/maven-spring-jdbc-example/

我还没有和豆类工作过,并从本教程有一件事困扰了我

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

    <bean id="customerDAO" class="com.mkyong.customer.dao.impl.JdbcCustomerDAO"> 
     <property name="dataSource" ref="dataSource" /> 
    </bean> 

    </beans> 

这是一个bean文件,其中包含以下教程一个将JDBCCustomerDao中的dataSource变量设置为dataSource的bean,它是包含在此文件中的另一个bean:

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> 

<bean id="dataSource" 
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 

    <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" /> 
    <property name="username" value="root" /> 
    <property name="password" value="password" /> 
</bean> 

我到目前为止了解到,从JdbcCustomerDao的数据源变量被设置为具有属性

 <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
    <property name="url" value="jdbc:mysql://localhost:3306/mkyongjava" /> 
    <property name="username" value="root" /> 
    <property name="password" value="password" /> 

但是我不知道该URL指向。是我的数据库可以找到的网址?它是我可以创建dbs的目录吗?

也许这个问题有一个非常简单的答案,但我并不确定,谷歌搜索并没有真正的帮助。

谢谢

回答

0

JDBC URL是驱动程序特定的。在这种情况下,它指向本地主机端口3306处的MySQL服务器到名为mkyongjava的数据库。

+0

为什么它在链接之前有一个“jdbc:mysql://”?不应该是localhost:3306/mkyongjava.sql? – Bula

+0

没有。你给我的URL有一个隐含的http://协议前缀。无论如何,第一部分必须是jdbc:,然后是JDBC驱动程序选择(在你的情况下是mysql:),然后是驱动程序特定部分,MySQL驱动程序将其解释为TCP连接的主机和端口,数据库连接到URL路径。 –