anrom SQL 开发

转载 2015年11月18日 11:48:51

1)mysql


DROP TABLE IF EXISTS `alihc_ad_spider_db`.`ad_spider_info`;
CREATE TABLE  `alihc_ad_spider_db`.`ad_spider_info` (
  `infoid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `urlPath` varchar(255) NOT NULL,
  `addTime` datetime DEFAULT NULL,
  `visitSalerId` bigint(20) unsigned DEFAULT NULL,
  `visitSaler` varchar(45) DEFAULT NULL,
  `comForm` varchar(45) DEFAULT NULL,
  `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`infoid`)
) ENGINE=InnoDB AUTO_INCREMENT=64 DEFAULT CHARSET=utf8;



2)application.conf


db.default.driver=com.mysql.jdbc.Driver  
db.default.url="jdbc:mysql://localhost:3306/db?characterEncoding=UTF-8"  
db.default.user="root"  
db.default.password="123"  


3)routes


GET     /adview_add_test                         controllers.AdViewTest.testadd



4)/modoule


package models


import java.util.Date
import scala.collection.immutable.HashSet
import scala.collection.Set
/*
CREATE TABLE `alibaba_ad_db`.`ad_spider_info` (
  `infoid` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `urlPath` VARCHAR(255) NOT NULL,
  `addTime` DATETIME NOT NULL,
  `visitSalerId` BIGINT UNSIGNED,
  `visitSaler` VARCHAR(45),
  `comForm` VARCHAR(45),
  `updateTime` TIMESTAMP NOT NULL,
  PRIMARY KEY (`infoid`)
)
ENGINE = InnoDB
CHARACTER SET utf8 COLLATE utf8_general_ci;

 */

case  class  AdSpiderInfo()
 {

   var  infoid :Long=0

   var  urlPath:String=""

   var  visitSalerId:Long=0


   var visitSaler:String=""

   var  comForm:String=""

   var updateTime:Date=new Date(System.currentTimeMillis())

   var addTime:Date=new Date(System.currentTimeMillis())

   def this(  infoid:Long,urlPath:String,visitSalerId:Long, visitSaler:String,comForm:String, addTime:Date,updateTime:Date){
     this()
      this.infoid=infoid
     this.urlPath=urlPath
     this.visitSalerId=visitSalerId
     this.visitSaler=visitSaler
     this.comForm=comForm
     this.addTime=addTime
     this.updateTime=updateTime

   }

    object AdSpiderInfo{

        var adlist = new HashSet( )

        def findAll{
            println("get adlist,")

          adlist
        }
    }

}



5)dao


package models

import anorm._
import models.AdSpiderInfo
import play.api.db.DB

import scala.collection.JavaConverters._
import scala.collection.immutable.List
import java.util.Date


import play.api.Play.current
/*

db lib: anorm


 */


object AdSpiderInfoDao{

    def save(entry: AdSpiderInfo): Unit ={


    }

  def show= {

    val conn = DB.getConnection()

    println("dbName:" + conn.getCatalog)
    //val result: Boolean = SQL("Select count(*) from  ad_spider_info").execute()


  }

  def count= {
    var countvl:Long =0
    DB.withConnection { implicit c  =>


      val firstRow = SQL("Select count(*) as c from ad_spider_info").apply().head
      val countryCount = firstRow[Long]("c")
      // println("count:" + countryCount)
      countvl=countryCount
    }
    countvl
  }

    //add data
  //test : ok
    def add(e:AdSpiderInfo):Boolean = {

      DB.withConnection {implicit c  =>

   
  val rs= SQL(
      """insert into
     ad_spider_info(urlPath, comForm,addTime,updateTime)
     values ({urlPath}, {comForm} ,{addTime},{updateTime})
      """)
     .on(
       "urlPath"->e.urlPath,
       "comForm"->e.comForm,
      //
       "addTime"->e.addTime,
      //
       //
       "updateTime"->None
     )
  .executeInsert()
        rs ==1
    }

    }

  def update(e:AdSpiderInfo):Boolean = {

    DB.withConnection {implicit c  =>


      val rs= SQL(
        """update
     ad_spider_info set urlPath={urlPath}, comFrome={comFrome},addTime={addTime},updateTime={updateTime} where infoid={infoid}
        """)
        .on(
          "urlPath"->e.urlPath,
          "comFrome"->e.comForm,
          "addTime"->e.addTime,
          "updateTime"->e.updateTime,
          "id"->e.infoid
        )
      .executeUpdate()
      rs == 1
    }

  }



  def delete(infoid:Long):Boolean = {

    DB.withConnection {implicit c  =>


      val rs= SQL(
        """delete from  ad_spider_info where infoid={infoid}
        """)
        .on(

          "id"->infoid
        )
       .executeUpdate()
      rs == 0
    }

  }

  /*
*/
  //query ad
  def getAdById(infoid: Long): AdSpiderInfoView = {

    var adSpiderInfo:AdSpiderInfoView=null

      DB.withConnection { implicit conn =>


      val sql: SqlQuery = SQL("Select * from  ad_spider_info where infoid={infoid} order by infoid desc")
//var infoid :Long, var urlPath:String,
//var addTime:Date,var visitSalerId:Long, var visitSaler:String,  var comForm:String, var updateTime:Date
     val list:List[AdSpiderInfoView]= sql().map(row =>
  AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
          ,row[Long]("visitSalerId"),
            row[String]("visitSaler"),row[String]("comForm"),row[Date]("updateTime"), row[Date]("addTime"))
        ).toList

      adSpiderInfo=   list.head
    }

    adSpiderInfo
  }

  //ad list page index

    def getListByPageIndex(index:Int, pageCount:Int,comForm:String): List[AdSpiderInfoView] ={

      val start:Int=(index-1)*pageCount

      var adSpiderInfolist: List[AdSpiderInfoView]=null

      DB.withConnection { implicit c =>


        val sql: SimpleSql[Row] = SQL("Select  * from  ad_spider_info  limit {start}, {pageCount} where comForm={comForm}")
        .on(
          "start"->start,
          "pageCount"->pageCount,
         "comForm"->comForm

        )
        //var infoid :Long, var urlPath:String,
        //var addTime:Date,var visitSalerId:Long, var visitSaler:String,  var comForm:String, var updateTime:Date
        val list:List[AdSpiderInfoView]= sql().map(row =>
          AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
            ,row[Long]("visitSalerId"),
            row[String]("visitSaler"),row[String]("comForm"), row[Date]("addTime"),row[Date]("updateTime"))
        ).toList

        adSpiderInfolist=   list
      }

      adSpiderInfolist
    }


  def getListAll(): List[AdSpiderInfoView]= {

    var adSpiderInfolist: List[AdSpiderInfoView]=null

    DB.withConnection { implicit c =>

      val sql: SqlQuery = SQL("Select  * from  ad_spider_info  order by infoid desc")

      //var infoid :Long, var urlPath:String,
      //var addTime:Date,var visitSalerId:Long, var visitSaler:String,  var comForm:String, var updateTime:Date
      val list: List[AdSpiderInfoView] = sql().map(row =>
        AdSpiderInfoView(row[Long]("infoid"), row[String]("urlPath")
          , row[Long]("visitSalerId"),
          row[String]("visitSaler"), row[String]("comForm"), row[Date]("addTime"), row[Date]("updateTime"))
      ).toList

      adSpiderInfolist = list
    }
      adSpiderInfolist
  }


  def  main (argvs:Array [String]){
     var  ifo=new AdSpiderInfo()
    ifo.urlPath="http://aabbcc.com/test.html"

    ifo.comForm="ali"

    this.add(ifo)

    println("aabbcc")
  }
}


6)controller


/**
 * Created by Administrator on 15-11-18.
 */
package  controllers

import java.util.Date

import controllers.AdView._
import models.{AdSpiderInfo, AdSpiderInfoDao}
import play.api.mvc.Action
import play.api.mvc.Controller
object AdViewTest extends  {

  def testadd=Action{

    var dao= AdSpiderInfoDao

    var  ifo=new AdSpiderInfo()
    ifo.urlPath="http://aabbcc.com/test.html"

    ifo.comForm="ali"

    var date=new Date(System.currentTimeMillis())

      ifo.addTime=date

    dao.add(ifo)

    var acount:Long=10
    Ok(views.html.adlist.render("AdSpider","{ifo}",acount) )
  }
}



相关文章推荐

Oracle PL/SQL开发入门(第五弹:运算符和表达式)

运算符类型赋值运算符赋值运算符使用:=,如:DECLARE v_variable1 VARCHAR2 (200) := 'This is a '; --定义变量变赋初值 ...

SQL Server数据库开发的二十一条军规

摘要:如果你正在负责一个基于SQL Server的项目,或者你刚刚接触SQL Server,你都有可能要面临一些数据库性能的问题,这篇文章会为你提供一些有用的指导(其中大多数也可以用于其它的DBMS)...

T-SQL开发——ID处理篇

数据库自增ID功能中Identity、Timestamp、Uniqueidentifier的区别: 问题现象: 一般序号的产生,对于一般程序员而言,都是使用T-SQL命令来实现。先读取表中的最大需...

Android开发之路十一-----SharePreferences进行数据存储和SQL数据库

SharedPreferences进行数据存储   很多时候我们开发的软件需要向用户提供软件参数设置功能,例如我们常用的QQ,用户可以设置是否允许陌生人添加自己为好友。对于软件配置参数的保存,如果...

SQL Server 开发指南---存储过程

SQL Server 存储过程    Transact-SQL中的存储过程,非常类似于Java语言中的方法,它可以重复调用。当存储过程执行一次后,可以将语句缓存中,这样下次执行的时候直接使用缓存中的语...

windows7家庭普通版(win7 home basic)安装SQL server 2005 开发版

windows7家庭普通版(win7 home basic)安装SQL server 2005 开发版(Developer Edition) 多亏了xys_777 的博客和boystraw 在论坛的...

使用Maven和Mybatis开发时,遇到“java.sql.SQLException: No suitable driver found for http://maven.apache.org”

今天使用Maven和Mybatis,在Eclipse上开发j2ee的程序。本人刚学Mybatis,对Maven还算熟悉,看过书,用的时间不长。本想试下Mybatis的selectList,结果程序编译...
  • lslxdx
  • lslxdx
  • 2012-02-20 22:14
  • 2309

本页的SQL例句全部懂了,你的数据库开发所需知识就够用了

--====================简单增删改=========== --查看学生表的全部数据 select * from studio    --插入一个新的学生信息 insert ...

Java开发者写SQL时常需要注意的8+13个地方

Java开发者写SQL时常需要注意的8+13个地方 (1)Understanding NULL Is this predicate correct with respect to NULL? ...

为jdbc开发一个小型sql语句生成器

spring的jdbc的使用,要么在daoImpl中继承jdbcDaoSupport,要么就使用注解注入,我一向倾向于使用注解。为了解决项目中一些重复的dao定义,我使用了如下泛型dao packa...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)