Advertisement
ahmadsm

contoh koneksi ke database mysql

Sep 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 4.53 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3.      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
  4.      xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
  5.      xmlns:aop="http://www.springframework.org/schema/aop" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
  6.      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  7.      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
  8.      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
  9.               http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
  10.               http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
  11.  
  12.     <context:annotation-config />
  13.     <!-- Sesuaikan dengan nama package dao (data access object) yang telah dibuat atau mau dibuat -->
  14.     <context:component-scan base-package="com.asm.dao" />
  15.    
  16.     <!-- Local Database -->  
  17.    <!--koneksi mysql-->
  18.     <bean id="dsGammu_1" class = "com.mchange.v2.c3p0.ComboPooledDataSource">
  19.         <property name="driverClass" value="com.mysql.jdbc.Driver" />
  20.         <property name="jdbcUrl" value="jdbc:mysql://172.168.100.72:3306/gammu_blast1" />
  21.         <property name="user" value="gammu_blast" />
  22.         <property name="password" value="4k53594mmu" />
  23.         <property name="minPoolSize" value="1" />
  24.         <property name="maxPoolSize" value="2" />
  25.         <property name="maxStatements" value="100" />
  26.         <property name="testConnectionOnCheckout" value="true" />
  27.     </bean>  
  28.     <bean id="entityManagerFactoryGammu_1" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
  29.         <property name="dataSource" ref="dsGammu_1"/>
  30.         <property name="loadTimeWeaver">
  31.             <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
  32.         </property>
  33.         <!-- Sesuaikan dengan nama package entity  yang telah atau mau dibuat -->
  34.         <property name="packagesToScan" value="com.acs.gammu.entity"/>
  35.         <property name="jpaVendorAdapter">
  36.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
  37.                 <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
  38.                   <!-- showsql = true sama dengan menampilkan sql atau query di log-->
  39.                 <property name="showSql" value="false" />
  40.                  <!-- generateddl= true  sama dengan create tables and fields in database (syarat database sudah tersedia, otomatis generate tabel dan column)-->
  41.                 <property name="generateDdl" value="false" />
  42.             </bean>
  43.         </property>
  44.         <property name="jpaProperties">
  45.             <props>
  46.                 <prop key="hibernate.format_sql">true</prop>
  47.             </props>
  48.         </property>
  49.     </bean>
  50.      <!-- transactionManagerInternal biasa dipakai buat aksi simpan, ubah, hapus, cari dll
  51.               contoh :
  52.               @Transactional(value = "transactionManagerGammu_1")
  53.               public void save(BusPendaftaran data) {
  54.               em.persist(data);
  55.               }
  56.  
  57.               @Transactional(value = "transactionManagerGammu_1")
  58.               public void update(BusPendaftaran data) {
  59.               em.merge(data);
  60.               }
  61.       -->
  62.     <bean id="transactionManagerGammu_1" class="org.springframework.orm.jpa.JpaTransactionManager">
  63.         <property name="rollbackOnCommitFailure" value="true" />
  64.         <property name="entityManagerFactory" ref="entityManagerFactoryGammu_1"/>
  65.         <property name="jpaDialect">
  66.             <bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
  67.         </property>
  68.     </bean>
  69.     <!-- sharedEntityManagerInternal = (Resource / EntityManager)
  70.               contoh :
  71.               @Resource(name = "sharedEntityManagerGammu_1")
  72.               private EntityManager em;
  73.       -->
  74.     <bean id="sharedEntityManagerGammu_1" name="sharedEntityManagerGammu_1" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
  75.         <property name = "entityManagerFactory" ref="entityManagerFactoryGammu_1"/>
  76.     </bean>
  77.     <tx:annotation-driven transaction-manager="transactionManagerGammu_1" />
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement