51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

测试开发精英班,通向高级软件测试工程师【周活动】 找茬--心里圈的故事 !【长期招募】博为峰网校招聘兼职讲师!横扫BAT,Python全栈测试开发技能大全
【108期】:我有自动化问题找joykao?双11剁手不吃土,来投稿赚回血红包! 【专题】用尽一切办法只为让你学好用例 自学软件测试那点事
查看: 3108|回复: 4

[翻译] 本人新手,在个外站上看见的文章,感觉可能有用,请论坛大神帮忙翻译下 谢谢啦

[复制链接]
  • TA的每日心情

    2014-10-30 19:12
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

    发表于 2013-8-15 16:03:40 | 显示全部楼层 |阅读模式

    以下是一段节选 全文在附件里 谢谢啦


    I was positively surprised to see how popular my recent listing about 10 Common Mistakes Java Developers Make when WritingSQL was, both on my ownblog and on my syndication partner DZone. The popularity shows acouple of things:

    ·
    How importantSQL is to the professional Java world.

    ·
    How common itis to forget about some basic SQL things.

    ·
    How wellSQL-centric libraries such as jOOQor MyBatis are responding tomarket needs, by embracing SQL. An amusing fact is that users have evenmentioned my blog post on SLICK’s mailing list. SLICK is a non-SQL-centric databaseaccess library in Scala. LikeLINQ (and LINQ-to-SQL) it focuses on language integration,not on SQL code generation.

    Anyway, the common mistakes I listed previously are far from complete, soI will treat you to a sequel of 10 subtly less common, yet equally interestingmistakes Java developers make when writing SQL.

    1. Not using PreparedStatements

    Interestingly, this mistake or misbelief still surfaces blogs, forumsand mailing lists many years after the appearance of JDBC, even if it is abouta very simple thing to remember and to understand. It appears that somedevelopers refrain from using PreparedStatements for any of these reasons:

    ·
    They don’tknow about PreparedStatements

    ·
    They thinkthat PreparedStatements are slower

    ·
    They thinkthat writing a PreparedStatement takes more effort

    First off, let’s bust the above myths. In 96% of the cases, you’re betteroff writing a PreparedStatement rather than a static statement. Why? For simplereasons:

    ·
    You can omitsyntax errors originating from bad string concatenation when inlining bindvalues.

    ·
    You can omitSQL injection vulnerabilities from bad string concatenation when inlining bindvalues.

    ·
    You can avoidedge-cases when inlining more “sophisticated” data types, such as TIMESTAMP,binary data, and others.

    ·
    You can keepopen PreparedStatements around for a while, reusing them with new bind valuesinstead of closing them immediately (useful in Postgres, for instance).

    ·
    You can makeuse of adaptive cursor sharing (Oracle-speak) in more sophisticateddatabases. This helps prevent hard-parsing SQL statements for every new set ofbind values.

    Convinced? Yes. Note, there are some rare cases when you actually want toinline bind values in order to give your database’s cost-based optimiser someheads-up about what kind of data is really going to be affected by the query.Typically, this results in “constant” predicates such as:

    ·
    DELETED = 1

    ·
    STATUS = 42

    But it shouldn’t result in “variable” predicates such as:

    ·
    FIRST_NAMELIKE “Jon%”

    ·
    AMOUNT >19.95

    Note that modern databases implement bind-variable peeking. Hence, bydefault, you might as well use bind values for all your query parameters. Notealso that higher-level APIs such as JPACriteriaQuery or jOOQwill help you generate PreparedStatements and bind values very easily andtransparently when writing embedded JPQL or embedded SQL.

    More background info:

    ·
    Caveats ofbind value peeking: An interesting blog post by Oracle Guru Tanel Poder on the subject

    ·
    Cursorsharing. An interesting Stack Overflow question.

    The Cure:

    By default, always use PreparedStatements instead of static statements. Bydefault, never inline bind values into your SQL.




    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有帐号?(注-册)加入51Testing

    x
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2019-8-9 10:30
  • 签到天数: 496 天

    连续签到: 1 天

    [LV.9]测试副司令

    发表于 2013-8-16 09:37:05 | 显示全部楼层
    以下是一段节选 全文在附件里 谢谢啦
    I was positively surprised to see how popular my recent listing  ...
    克拉星空 发表于 2013-8-15 16:03



        英文不好的,帮顶!
    回复 支持 反对

    使用道具 举报

    该用户从未签到

    发表于 2013-8-30 10:10:19 | 显示全部楼层
    第一段内容是讲他写的十件TAV开发者使用SQL时常犯的十个错误。
    SQL会影响JAVA程序的专业性,并且人人常常忘记关于SQL最基本要注意的事情。
    下面他将列出这十个常见的错误。
    其实就是讲SQL在JAVA开发过程中遇到的一些问题。你只需要看看标题,然后看一下他的列出的reason,然后分析一下他举得例子即可。不需要每句话都看,有些只是他自己的感想。
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    奋斗
    2015-11-22 11:20
  • 签到天数: 78 天

    连续签到: 1 天

    [LV.6]测试旅长

    发表于 2013-8-30 17:00:25 | 显示全部楼层
    多写几个中文注释下嘛
    回复 支持 反对

    使用道具 举报

  • TA的每日心情

    2014-10-30 19:12
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]测试小兵

     楼主| 发表于 2013-9-3 08:51:01 | 显示全部楼层
    回复 3# Geiler

    这样呀,谢谢啦
    回复 支持 反对

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2019-11-19 19:14 , Processed in 0.073335 second(s), 31 queries .

    Powered by Discuz! X3.2

    © 2001-2019 Comsenz Inc.

    快速回复 返回顶部 返回列表