Using Leopard JDBC

Source: Internet
Author: User

Use leopard jdbc to learn how to use leopard jdbc.

This guide will guide you through the operation of MySQL using leopard jdbc.

How to complete the This guide

You can start from scratch and complete each step, or you can bypass the basic setup steps you're already familiar with. Either way, you can end up with working code.

1. Configure MAVEN Dependencies

In the DAO module, Pom.xml joins

    <dependencies>        [...]        <dependency>            <groupId>io.leopard</groupId>            <artifactid>leopard-data</ artifactid>            <version>0.0.1-SNAPSHOT</version>        </dependency>        [...]    </dependencies>    <repositories>        <repository>            <id>leopard-snapshots</id >            <name>leopard snapshots</name>            <url>http://leopard.io/nexus/content/ repositories/snapshots/</url>        </repository>    </repositories>
2. Configure Spring

site-dao/src/main/resources/applicationContext-dao.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:leopard= "Http://www.leopard.io/schema/leopard" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsdhttp://www.leopard.io/schema/leopard http://www.leopard.io/schema/leopard.xsd "><leopard: Component-scan base-package= "Io.leopard.site"/><leopard:jdbc id= "jdbc" host= "112.126.75.27" database= " Example "user=" Example "password=" Leopard "/><leopard:redis id=" Redis "server=" 112.126.75.27:6311 "/></ Beans>
3. Using the JDBC interface

Createsite-dao/src/main/java/io/leopard/site/dao/mysql/UserDaoMyqlImpl.java

Package Io.leopard.site.dao.mysql;import Io.leopard.data4j.jdbc.jdbc;import Io.leopard.data4j.jdbc.builder.insertbuilder;import Io.leopard.site.model.user;import Javax.annotation.Resource; Import org.springframework.stereotype.Repository; @Repositorypublic class Userdaomyqlimpl {@Resourceprivate jdbc jdbc ;p ublic boolean Add (user user) {Insertbuilder builder = new Insertbuilder ("User"), Builder.setlong ("UID", User.getuid ()) ; Builder.setstring ("Passport", User.getpassport ()), Builder.setstring ("nickname", User.getnickname ()); Builder.setdate ("Posttime", User.getposttime ()); return This.jdbc.insertForBoolean (builder); Public User get (long uid) {String sql = ' SELECT * from User where uid=? '; return this.jdbc.query (SQL, user.class);} Public boolean Delete (long uid) {String sql = ' Delete from user where uid=? '; return This.jdbc.updateForBoolean (SQL, UID);}}
Summarize

Congratulations to you! You can already use Leopard Jdbc in your old project configuration, although the functionality is relatively simple, you can expand your business system on this basis and wish you good luck.

Using leopard Jdbc

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.