<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 165, comments - 198, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    ?? 這些日子一直在想,將來的我怎么在技術這條道路上好好走下去(這一輩子我都會干技術的,我相信我自己)。
    ??? 想著想著慢慢的開始害怕自己被淘汰。我才24歲就我工作的一年半中,就看到太多太多的技術被更替,被淘汰。又太多的新技術出現在我們面前。我這年努力去追趕(學習新技術就是一種投資^_^)
    ??? 應該要有些壓箱底的東西!就今天開始先學數學;后數據結構;最后算法。我要把原來大學學的一點一點撿回來了。

    學習之前給自己找個數學學習工具;
    Scilab logo
    scilab(開源)?http://www.scilab.org/
    ??? ?? (參考)? http://blog.chinaunix.net/u/7217/article_40744.html
    ??? ?? ?? ?? ?? http://blog.chinaunix.net/u1/56796/showart_694786.html
    與之對應的 matlab(企業)對現在我來說太大了





    scilab安裝后運行
    在命令行寫入(運行后):
    A=[1 2 3 4;5 6 7 8]

    hist3d(A);





    posted @ 2008-06-09 16:58 G_G 閱讀(1918) | 評論 (3)編輯 收藏

    就用數據數據庫表地址數據(中國地區)來說吧
    存儲過程:
    DELIMITER?//
    drop?procedure?if?exists??useCursor?//
    create?temporary?table?if?not?exists??aop.tmp_table(data?bigint(20))//

    //建立存儲過程
    CREATE?PROCEDURE?useCursor(iid?bigint(20))
    ????
    BEGIN
    ??? ?? ? //局部變量定義
    ?????????declare?tid?bigint(20)?default?-1?;
    ????????
    ??? ?? ? //游標定義
    ?????????
    declare?cur1?CURSOR?FOR?select?id?from?aop.location?where?fid=iid?;
    ????????
    //游標介紹定義
    ???????? declare
    ?CONTINUE?HANDLER?FOR?SQLSTATE?'02000'?SET?tid?=?null;
    ????????
    ???????? //開游標
    ???????? OPEN?cur1;
    ??????
    ? FETCH?cur1?INTO?tid;

    ????????
    WHILE?(?tid?is?not?null?)?
    ???????? DO
    ??????????
    insert?into?aop.tmp_table?values(tid);
    ??? ?? ?? //樹形結構數據遞歸收集到建立的臨時表中
    ??????????call?useCursor(tid);
    ?????????
    FETCH?cur1?INTO?tid?;
    ???????
    END?WHILE;
    ????
    END;//
    DELIMITER?;

    //查詢開始 ,運行是成功的,但用時有10多秒之多,才幾百條數據;
    //望那個大牛 幫幫解決下時間問題!

    call?useCursor(
    1);
    select?*?from?tmp_table?;
    drop?temporary?table?if??exists??aop.tmp_table?;


    結果:

    |??187?|
    |??188?|
    |??189?|
    |??190?|
    |??191?|
    |??192?|
    |??193?|
    |??194?|
    |??195?|
    |??196?|
    |??197?|
    |??198?|
    |??199?|
    |??200?|
    |??201?|
    |??202?|
    |??203?|
    |??204?|
    |??205?|
    |??206?|
    |??207?|
    |??208?|
    |??209?|
    .

    posted @ 2008-06-08 16:33 G_G 閱讀(2773) | 評論 (2)編輯 收藏



    ???? public ? static ?String?filter(String?input)?{
    ????????
    if ?(input? == ? null )?{
    ????????????
    return ? null ;
    ????????}
    ????????StringReader?stringReader?
    = ? new ?StringReader(input);
    ????????BufferedReader?reader?
    = ? new ?BufferedReader(stringReader);

    ????????StringBuffer?ret?
    = ? new ?StringBuffer(input.length()? + ? 200 ); // ?add?more?room?to?the?result?String

    ????????String?line?
    = ? null ;
    ????????
    try ?{
    ??? ?? ?? ? //換行后添加<br/>
    ????????????
    while ?((line? = ?reader.readLine())? != ? null )?{
    ??? ?? ?? ?? ?? //wap 對 <? >的替換
    ????????????????ret.append(line.replaceAll(
    " < " ,? " &lt; " ).replaceAll( " > " ,? " &gt; " ). replaceAll( "&",?"&amp;" ) ).append( " <br/>&nbsp;&nbsp; " );
    ????????????}
    // while
    ????????????
    // 如果是最后一行
    ????????}? catch ?(IOException?ex)?{}

    ???????
    return ? " &nbsp;&nbsp; " + ret.toString()?;

    ????}

    ????

    posted @ 2008-06-04 17:19 G_G 閱讀(236) | 評論 (0)編輯 收藏

    官方:
    BaseX Logo
    eg:xquery使用
    import?org.basex.core.Commands;
    import?org.basex.core.proc.Proc;
    import?org.basex.data.Result;
    import?org.basex.io.ConsoleOutput;
    import?org.basex.query.QueryException;
    import?org.basex.query.QueryProcessor;
    import?org.basex.query.xquery.XQueryProcessor;

    /**
    ?*?This?class?serves?an?example?for?executing?XQuery?requests.
    ?
    */
    public?final?class?XQueryExample?{
    ??
    /**?Sample?query.?*/
    ??
    private?static?final?String?XMLFILE?=?XPathExample.class.getClassLoader().getSystemResource(
    ??????????????
    "xx.xml"
    ?????????).getPath();
    ??
    ??
    ??
    private?static?final?String?QUERY?=?"?for?$x?in?doc('"+XMLFILE+"')//property?"?+
    ??????????????????????????????????????????????
    "?return?<child>{data($x/@name)}</child>";

    ??
    /**?Private?constructor.?*/
    ??
    private?XQueryExample()?{?}
    ??
    /**
    ???*?Main?method?of?the?example?class.
    ???*?
    @param?args?(ignored)?command-line?arguments
    ???*?
    @throws?Exception?exception
    ???
    */
    ??
    public?static?void?main(final?String[]?args)?throws?Exception?{

    ????
    //?FIRST?EXAMPLE:
    ????System.out.println("First?example:");

    ????
    //?create?standard?output?stream
    ????final?ConsoleOutput?out?=?new?ConsoleOutput(System.out);

    ????
    //?Create?a?BaseX?process
    ????final?Proc?proc?=?Proc.get(Commands.XQUERY,?QUERY);
    ????
    //?launch?process
    ????if(proc.execute())?{
    ??????
    //?successful?execution:?print?result
    ??????proc.output(out);
    ????}?
    else?{
    ??????
    //?execution?failed:?print?result
    ??????proc.info(out);
    ????}
    ????out.flush();
    ????System.out.println();
    ????
    ????
    //?SECOND?EXAMPLE?(ALTERNATIVE):
    ????System.out.println("Second?example:");

    ????
    //?Execute?XQuery?request
    ????try?{
    ??????
    //?create?query?instance
    ??????final?QueryProcessor?xquery?=?new?XQueryProcessor(QUERY);
    ??????
    //?execute?query;?no?initial?context?set?is?specified?(null)
    ??????final?Result?result?=?xquery.query(null);
    ??????
    //?print?output
    ??????result.serialize(out,?false);
    ??????out.println();
    ????}?
    catch(final?QueryException?e)?{
    ??????
    //?dump?stack?trace
    ??????e.printStackTrace();
    ????}

    ????
    //?close?output?stream
    ????out.close();
    ??}
    }


    結果:
    First?example:
    <child>connection.datasource</child>
    <child>dialect</child>
    <child>show_sql</child>
    <child>hibernate.cache.provider_class</child>
    <child>cache.use_query_cache</child>

    Second?example:
    <child>connection.datasource</child>
    <child>dialect</child>
    <child>show_sql</child>
    <child>hibernate.cache.provider_class</child>
    <child>cache.use_query_cache</child>


    數據來源:
    xx.xml
    <?xml?version='1.0'?encoding='utf-8'?>

    <hibernate-configuration>

    ????
    <session-factory>

    ????????
    <property?name="connection.datasource">java:comp/env/jdbc/USERPORTAL1</property>
    ????????
    <property?name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
    ?????????
    <property?name="show_sql">true</property>
    ?????????
    <property?name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
    ?????????
    <property?name="cache.use_query_cache">true</property>
    ????
    <!--?JDBC?connection?pool?(use?the?built-in)?-->

    ????
    </session-factory>

    </hibernate-configuration>


    posted @ 2008-06-04 16:04 G_G 閱讀(1761) | 評論 (0)編輯 收藏

    xml 數據庫使用,和XQuery使用.
    環境:
    ??? 1.xml數據庫使用(參考:eXistQuick Start
    ??? 2.xQuery XQuery 首頁
    ???
    1.測試開始:
    ??? 進入:eXist-> http://demo.exist-db.org/xmldb/db/?
    for $x in doc("/examples2.xml")/exist:result/country return if ($x/population_growth<-1) then <child>{data($x/name)}</child> else <adult>{data($x/name)}</adult>
    parent collection: /db
    <child > Bosnia and Herzegovina </ child >
    <adult > Czech Republic </ adult >
    <child > Estonia </ child >
    <child > Faroe Islands </ child >
    <adult > Hungary </ adult >
    <adult > Ireland </ adult >
    <child > Latvia </ child >
    <adult > Lithuania </ adult >
    <child > Romania </ child >
    <adult > Russia </ adult >

    使用數據:
    ??? http://demo.exist-db.org/xmldb/db/examples2.xml


    2:自定義方法:
    ??? 使用:http://demo.exist-db.org/sandbox/sandbox.xql
    ???
    declare?function?local:minPrice(){
    ??
    for?$x?in?(1?to?5)
    ??
    return?<test>{$x}</test>
    };

    <minPrice>{local:minPrice()}</minPrice>
    結果:
    <
    minPrice>
    <test>1</test>
    <test>2</test>
    <test>3</test>
    <test>4</test>
    <test>5</test>
    </minPrice>




    posted @ 2008-05-29 14:49 G_G 閱讀(1182) | 評論 (1)編輯 收藏

         摘要: 為方便項目使用,特留!表結構:Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->?CREATE?TABLE?`location`?(??`id`?bigint(20)?NOT?NULL?auto_increment,??`name`?varchar(50...  閱讀全文

    posted @ 2008-05-29 10:51 G_G 閱讀(5276) | 評論 (6)編輯 收藏

    參考:第?9?章?事務管理 - Spring Framework reference 2.0.5 參考手冊中文版
    http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch09.html

    先從配置文件開始:
    源碼:springAop.rar

    需要jar
    <?xml?version="1.0"?encoding="UTF-8"?>
    <classpath>
    ????
    <classpathentry?kind="src"?path="java"/>
    ????
    <classpathentry?kind="con"?path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    ????
    <classpathentry?kind="lib"?path="lib/aspectjrt.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/aspectjweaver.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/spring.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/spring-sources.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/commons-logging-1.0.4.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/cglib-nodep-2.1_3.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/hibernate3.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/log4j-1.2.11.jar"/>
    ????
    <classpathentry?kind="con"?path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
    ????
    <classpathentry?kind="lib"?path="lib/dom4j-1.6.1.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/commons-collections-2.1.1.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/mysql.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/jta.jar"/>
    ????
    <classpathentry?kind="lib"?path="lib/antlr-2.7.6.jar"/>
    ????
    <classpathentry?kind="output"?path="bin"/>
    </classpath>


    spring 配置
    <?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:aop
    ="http://www.springframework.org/schema/aop"
    ????xmlns:tx
    ="http://www.springframework.org/schema/tx"
    ????xsi:schemaLocation
    ="http://www.springframework.org/schema/beans?
    ??http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    ??http://www.springframework.org/schema/aop?
    ??http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
    ??http://www.springframework.org/schema/tx?
    ??http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
    >

    ????
    <!--?demo?start?-->
    ????
    <import?resource="demo_spring.xml"?/>
    ????
    <!--?demo?end?-->

    ????
    <bean?id="dataSource"
    ????????class
    ="org.springframework.jdbc.datasource.DriverManagerDataSource">
    ????????
    <property?name="driverClassName"
    ????????????value
    ="com.mysql.jdbc.Driver">
    ????????
    </property>
    ????????
    <property?name="url"
    ????????????value
    ="jdbc:mysql://localhost:3306/aop?characterEncoding=utf8">
    ????????
    </property>
    ????????
    <property?name="username"?value="root"></property>
    ????????
    <property?name="password"?value=""></property>
    ????
    </bean>

    ????
    <!--?hibernate3?sessionFactory??-->
    ????
    <bean?id="sessionFactory"
    ????????class
    ="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    ????????
    <!--?此次??為?spring?事務需要使用?dataSource?;為空事務由Hibernian自己維護?-->
    ????????
    <property?name="dataSource"?ref="dataSource"?/>
    ????????
    <property?name="configLocation"
    ????????????value
    ="classpath:hibernate.cfg.xml"?/>
    ????
    </bean>



    ????
    <!--?事務適配器?-->
    ????
    <bean?id="txManager"
    ????????class
    ="org.springframework.orm.hibernate3.HibernateTransactionManager">
    ????????
    <property?name="sessionFactory"?ref="sessionFactory"?/>
    ????
    </bean>






    ????
    <!--?aop?與事務聯系?aopBean<->txAdvice??-->
    ????
    <aop:config>
    ????????
    <!--?邏輯攔截?-->
    ????????
    <aop:pointcut?id="demoAopBean"
    ????????????expression
    ="execution(*?demo*.*.*(..))"?/>
    ????????
    <aop:advisor?advice-ref="demoTxAdvice"
    ????????????pointcut-ref
    ="demoAopBean"?/>
    ????
    </aop:config>

    ????
    <!--?事務原子?具體方法進行什么事務?-->
    ????
    <tx:advice?id="demoTxAdvice"?transaction-manager="txManager">
    ????????
    <tx:attributes>
    ????????????
    <tx:method?name="get*"?propagation="SUPPORTS"
    ????????????????read-only
    ="true"?rollback-for="NoProductInStockException"?/>
    ????????????
    <tx:method?name="save*"?propagation="REQUIRED"
    ????????????????rollback-for
    ="NoProductInStockException"?/>
    ????????????
    <tx:method?name="update*"?propagation="REQUIRED"
    ????????????????rollback-for
    ="NoProductInStockException"?/>
    ????????????
    <tx:method?name="remove*"?propagation="REQUIRED"
    ????????????????rollback-for
    ="NoProductInStockException"?/>
    ????????????
    <tx:method?name="*"?propagation="SUPPORTS"
    ????????????????rollback-for
    ="NoProductInStockException"?/>
    ????????
    </tx:attributes>
    ????
    </tx:advice>



    ????
    <!--?daoCalss?:?extends?HibernateDaoSupport?implements?BeanDao?-->
    ????
    <bean?id="beanDao"
    ????????class
    ="demo.springHibernate.dao.imp.BeanDaoImp">
    ????????
    <property?name="sessionFactory">
    ????????????
    <ref?bean="sessionFactory"></ref>
    ????????
    </property>
    ????
    </bean>


    ????
    <bean?id="helloAction"?class="demo.struts2Spring.HelloWorld"
    ????????scope
    ="prototype">
    ????????
    <property?name="bds"?ref="beanDao"></property>
    ????
    </bean>
    ????
    </beans>


    hibernate 配置
    <?xml?version="1.0"?encoding="UTF-8"?>
    <!DOCTYPE?hibernate-configuration?PUBLIC
    ????????"-//Hibernate/Hibernate?Configuration?DTD?3.0//EN"
    ????????"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
    >
    <hibernate-configuration>
    <session-factory?name="asdf">
    ????
    <property?name="hibernate.dialect">mysql</property>
    ????
    <property?name="myeclipse.connection.profile">
    ????????com.mysql.jdbc.Driver
    ????
    </property>
    ????
    <property?name="connection.url">
    ????????jdbc:mysql://localhost/aop
    ????
    </property>
    ????
    <property?name="show_sql">true</property>
    ????
    ????
    <property?name="connection.username">root</property>
    ????
    <property?name="connection.password"></property>
    ????
    <property?name="connection.driver_class">
    ????????com.mysql.jdbc.Driver
    ????
    </property>
    ????
    <property?name="dialect">
    ????????org.hibernate.dialect.MySQLDialect
    ????
    </property>
    ????
    ????
    <mapping?resource="bean/UnitBean.hbm.xml"?/>
    ????
    </session-factory>
    </hibernate-configuration>


    dao 類(接口)
    package?dao.imp;

    import?java.util.List;

    import?org.springframework.orm.hibernate3.support.HibernateDaoSupport;

    import?bean.UnitBean;

    import?dao.BeanDao;

    public?class?BeanDaoImp?extends?HibernateDaoSupport?implements?BeanDao{
    ????
    public?void?addBean(UnitBean?unitBean)?{
    ????????
    this.getHibernateTemplate().save(unitBean);
    ????}

    ????
    public?List<UnitBean>?getBeanByAll()?{
    ????????
    return?this.getHibernateTemplate().find("?from?"+UnitBean.class.getName());
    ????}

    ????
    public?void?removeBean(long?beanId)?{
    ????????
    this.getHibernateTemplate().delete(
    ????????????????getHibernateTemplate().get(UnitBean.
    class,?beanId)
    ????????????);
    ????}
    ????
    }

    Main 類
    package?unit;

    import?org.springframework.context.ApplicationContext;
    import?org.springframework.context.support.ClassPathXmlApplicationContext;

    import?dao.BeanDao;
    import?bean.UnitBean;

    public?class?Main?{
    ????
    public?static?void?main(String[]?args)?{
    ???????????ApplicationContext?ctx?
    =?new?ClassPathXmlApplicationContext("beans.xml");
    ???????????BeanDao?dao?
    =?(BeanDao)?ctx.getBean("beanDao");
    ???????????UnitBean?bean?
    =?new?UnitBean();
    ???????????bean.setName(
    "xx");
    ???????????bean.setPass(
    "11");
    ???????????dao.addBean(bean);
    ???????????
    ???????????
    for(UnitBean?unitBean?:?dao.getBeanByAll()?){
    ???????????????System.out.println(?unitBean.getId()?);
    ???????????}
    ???????????
    ???????????dao.removeBean(bean.getId());
    ???????????
    ????}
    }
    結果:
    Hibernate: insert into bean (name, pass) values (?, ?)
    Hibernate: select unitbean0_.id as id0_, unitbean0_.name as name0_, unitbean0_.pass as pass0_ from bean unitbean0_
    1
    Hibernate: select unitbean0_.id as id0_0_, unitbean0_.name as name0_0_, unitbean0_.pass as pass0_0_ from bean unitbean0_ where unitbean0_.id=?
    Hibernate: delete from bean where id=?






    posted @ 2008-05-09 13:47 G_G 閱讀(3156) | 評論 (0)編輯 收藏

    我的aop 基礎
    spring 實際使用 (這就使用一個例子說明)

    測試類以及結果:
    package?unit;

    import?org.springframework.context.ApplicationContext;
    import?org.springframework.context.support.ClassPathXmlApplicationContext;

    import?bean.HelloService;

    public?class?Main?{
    ????
    public?static?void?main(String[]?args)?{
    ???????????ApplicationContext?context?
    =?new?ClassPathXmlApplicationContext(??????
    ???????????????????
    "beans.xml");????
    ???????????HelloService?service?
    =?(HelloService)?context.getBean("helloService");????
    ???????????service.annotationAop();
    ???????????
    ???????????System.out.println();
    ???????????
    ???????????service.xmlAop();
    ???????????
    ????}
    }
    結果:
    ?annotationAop//正常方法運行
    aop--AspectJ!?//
    annotation攔截

    ?xmlAop?
    //正常方法運行
    ?aop--XmlAop! //配置攔截



    use jar
    • --aspectjrt.jar
    • --aspectjweaver.jar
    • --acglib-nodep-2.1_3.jar
    • --commons-logging.jar
    • --spring.jar
    • --spring-aspects.jar
    XML配置
    <beans?xmlns="http://www.springframework.org/schema/beans"???????
    ????????????xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance"
    ????????????xmlns:aop
    ="http://www.springframework.org/schema/aop"
    ???????????????xsi:schemaLocation
    =????????
    ???????????????????"http://www.springframework.org/schema/beans?????????
    ???????????????????http://www.springframework.org/schema/beans/spring-beans.xsd?????????
    ???????????????????http://www.springframework.org/schema/aop?????????
    ???????????????????http://www.springframework.org/schema/aop/spring-aop.xsd"
    >
    ????????
    ????????
    <!--?測試使用類?分別由?方法?annotationAop/xmlAop?-->
    ????????
    <bean?id="helloService"???????
    ????????????class
    ="bean.HelloService"/>????
    ????????
    ????????????
    ????????
    <!--?annotation?aop?攔截?使用@Aspect?
    ????????????@Pointcut("execution(*?annotationAop(..))")??
    ????????????@AfterReturning("mainMethod()")??
    ????????
    -->
    ????????
    <bean?id="xmlAop"?
    ????????????class
    ="aop.AnnotationAspectJ"/>
    ????????
    <aop:aspectj-autoproxy/>????
    ????????
    ????????
    ????????
    <!--?xml?aop??配置文件攔截?-->
    ????????
    <bean?id="XmlAspectJ"???????
    ????????????class
    ="aop.XmlAspectJ"/>
    ????????
    <aop:config>?????
    ?????????????
    <aop:aspect?ref="XmlAspectJ">
    ?????????????????
    <aop:pointcut?id="mainMethod"?expression="execution(*?xmlAop(..))"/>????
    ?????????????????
    <aop:after-returning?pointcut-ref="mainMethod"?method="goXmlAop"/>?????
    ?????????????
    </aop:aspect>???
    ?????????
    </aop:config>????
    ????????????
    </beans>

    HelloService.java
    package?bean;

    public?class?HelloService?{??
    ????
    public?void?annotationAop()?{????
    ????????System.out.println(
    "?annotationAop?");
    ????}
    ????
    ????
    public?void?xmlAop(){
    ????????System.out.println(
    "?xmlAop?");
    ????}
    }

    AnnotationAspectJ.java
    package?aop;

    import?org.aspectj.lang.annotation.AfterReturning;
    import?org.aspectj.lang.annotation.Aspect;
    import?org.aspectj.lang.annotation.Pointcut;

    @Aspect
    public?class?AnnotationAspectJ?{??
    ????@Pointcut(
    "execution(*?annotationAop(..))")??
    ????
    public?void?mainMethod()?{}??
    ????
    ????@AfterReturning(
    "mainMethod()")??
    ????
    public?void?sayHello()?{????
    ????????System.out.println(
    "aop--AspectJ!");??
    ????}
    }

    XmlAspectJ.java
    package?aop;

    public?class?XmlAspectJ?{
    ????
    public?void?goXmlAop(){
    ????????System.out.println(
    "?aop--XmlAop!?");
    ????}
    }













    posted @ 2008-05-08 10:08 G_G 閱讀(4329) | 評論 (1)編輯 收藏

    這就不介紹了 代碼上:
    package?unit;

    import?java.util.regex.Matcher;
    import?java.util.regex.Pattern;

    import?org.junit.Assert;
    import?org.junit.Test;

    public?class?RegexUnit?{


    ????@Test
    ????
    /**
    ?????*?<p>向前\向后查找</p>
    ?????
    */
    ????
    public?void?unit9()throws?Exception{
    ????????String?testStr?
    =?"http://www.google.com";
    ????????
    ????????
    /*?一般查找
    ?????????*?.+(:)?查詢出結果包含?:
    ?????????
    */
    ????????Pattern?pattern?
    =?Pattern.compile(".+(:)");????????
    ????????Matcher?matcher?
    =??pattern.matcher(testStr);
    ????????????Assert.assertTrue(
    "錯誤:?查找出結果通過?.+(:)?此regex沒有包含?:?",
    ????????????????????matcher.find()?
    &&?matcher.group().equals("http:")?);
    ????????
    ????????
    /*??向前查找
    ?????????*??.+(?=:)?查詢結果不包含?:
    ?????????
    */
    ????????Pattern?pattern2?
    =?Pattern.compile(".+(?=:)");
    ????????Matcher?matcher2?
    =?pattern2.matcher(testStr);
    ????????????Assert.assertTrue(
    "錯誤:?查找出結果通過?.+(?=:)?此regex有包含?:?",
    ????????????????????matcher2.find()
    &&?matcher2.group().equals("http"));
    ????????
    /*?向后查找
    ?????????*?(?<=:).+
    ?????????
    */
    ????????Pattern?pattern3?
    =?Pattern.compile("(?<=://).+");
    ????????Matcher?matcher3?
    =?pattern3.matcher(testStr);
    ????????????Assert.assertTrue(
    "錯誤:查找出結果包含?http://?不向后查詢",
    ????????????????????matcher3.find()
    &&?matcher3.group().equals("www.google.com")?);
    ????}


    ????@Test
    ????
    /**?回朔應用?
    ?????*??查詢回朔、回朔替換、回朔大小寫替換
    ?????
    */
    ????
    public?void?unit8()throws?Exception{
    ????????String?testStr?
    =?"this?is?a?block?of?of?test,"+
    ????????????????????????????
    "?several?words?here?are?are?"?+
    ????????????????????????????
    "?repeated?,?and?and?they?should?not?be.?";
    ????????
    ????????Pattern?pattern?
    =?Pattern.compile("[?]+(\\w+)[?]+\\1");
    ????????Matcher?matcher?
    =?pattern.matcher(testStr);
    ????????
    //查詢結果?are?are?
    ????????Assert.assertTrue("錯誤:regex?不匹配?",?
    ????????????????matcher.find()
    &&matcher.group().split("?").length>=2?);
    ????????
    ????????
    while(?matcher.find()?){
    ????????????Assert.assertTrue(
    "錯誤:regex?不匹配?",?
    ????????????????????matcher.group().split(
    "?").length>=2?);
    ????????}
    ????????
    ????????
    ????????
    //替換
    ????????String?testStr2s?=?"313-555-1234";
    ????????Pattern?pattern2?
    =?Pattern.compile("(\\d{3})(-)(\\d{3})(-)(\\d{4})");
    ????????Matcher?mtmp?
    =??pattern2.matcher(testStr2s);
    ????????Assert.assertTrue(
    "錯誤:沒有查替換",
    ????????????????mtmp.find()?
    &&?
    ????????????????????mtmp.replaceAll(
    "($1)?$3-$5").equals("(313)?555-1234")?);
    ????????
    ????????
    ????????
    /*大小寫替換(java?不能成功)
    ?????????*??\E?結束?\L?或?\U轉換
    ?????????*??\l??\L?把下一個字符(串)換為小寫
    ?????????*??\?u??\U?把下一個字符(串)轉換為大寫
    ??? ?? ? *? 此中
    (.*?)懶散加載
    ?????????*/
    ????????String?testStr3?
    =?"tt:google:xx";
    ????????Pattern?pattern3?
    =?Pattern.compile("(?<=:)(.*?)(?=:)");
    ????????Matcher?matcher2?
    =?pattern3.matcher(testStr3);
    ????????
    if(?matcher2.find())
    ????????????System.out.println(?matcher2.group()?)?;
    ????}
    ????
    ????
    }



    posted @ 2008-05-04 09:59 G_G 閱讀(2270) | 評論 (3)編輯 收藏

    MySQL 存取控制包含2個階段:

    • 階段1:服務器檢查是否允許你連接。
    • 階段2:假定你能連接,服務器檢查你發出的每個請求。看你是否有足夠的權限實施它。例如,如果你從數據庫表中選擇(select)行或從數據庫刪除表,服務器確定你對表有SELECT權限或對數據庫有DROP權限。
    參考 : 5.8. MySQL用戶賬戶管理

    1.權限查看
    mysql>?show?grants?for?'root'@'localhost'?;
    +---------------------------------------------------------------------+
    |?Grants?for?root@localhost???????????????????????????????????????????|
    +---------------------------------------------------------------------+
    |?GRANT?ALL?PRIVILEGES?ON?*.*?TO?'root'@'localhost'?WITH?GRANT?OPTION?|
    +---------------------------------------------------------------------+
    1?row?in?set?(0.06?sec)

    2.權限設置
    5.8.2. 向MySQL增加新用戶賬戶
    mysql>?GRANT?ALL?PRIVILEGES?ON?*.*?TO?'monty'@'localhost'
    ????
    ->?????IDENTIFIED?BY?'some_pass';

    mysql
    >?GRANT?ALL?PRIVILEGES?ON?*.*?TO?'monty'@'%'
    ????
    ->?????IDENTIFIED?BY?'some_pass'?WITH?GRANT?OPTION;
    ?? 其中兩個賬戶有相同的用戶名monty和密碼some_pass。兩個賬戶均為超級用戶賬戶,具有完全的權限可以做任何事情。一個賬戶 ('monty'@'localhost')只用于從本機連接時。另一個賬戶('monty'@'%')可用于從其它主機連接。


    mysql>?GRANT?RELOAD,PROCESS?ON?*.*?TO?'admin'@'localhost';
    該賬戶只用于從本機連接。授予了RELOADPROCESS管理權限。這些權限允許admin用戶執行mysqladmin reloadmysqladmin refreshmysqladmin flush-xxx命令,以及mysqladmin processlist。未授予訪問數據庫的權限。你可以通過GRANT語句添加此類權限。

    mysql
    >?GRANT?USAGE?ON?*.*?TO?'dummy'@'localhost';
    ??? 一個賬戶有用戶名dummy,沒有密碼。該賬戶只用于從本機連接。未授予權限。通過GRANT語句中的USAGE權限,你可以創建賬戶而不授予任何權限。它可以將所有全局權限設為'N'。假定你將在以后將具體權限授予該賬戶。

    下面的例子創建3個賬戶,允許它們訪問專用數據庫。每個賬戶的用戶名為custom,密碼為obscure

    mysql
    >?GRANT?SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ????
    ->?????ON?bankaccount.*
    ????
    ->?????TO?'custom'@'localhost'
    ????
    ->?????IDENTIFIED?BY?'obscure';

    mysql
    >?GRANT?SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ????
    ->?????ON?expenses.*
    ????
    ->?????TO?'custom'@'whitehouse.gov'
    ????
    ->?????IDENTIFIED?BY?'obscure';

    mysql
    >?GRANT?SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
    ????
    ->?????ON?customer.*
    ????
    ->?????TO?'custom'@'server.domain'
    ????
    ->?????IDENTIFIED?BY?'obscure';

    這3個賬戶可以用于:

    ·?????????第1個賬戶可以訪問bankaccount數據庫,但只能從本機訪問。

    ·?????????第2個賬戶可以訪問expenses數據庫,但只能從主機whitehouse.gov訪問。

    ·?????????第3個賬戶可以訪問customer數據庫,但只能從主機server.domain訪問。

    要想不用GRANT設置custom賬戶,使用INSERT語句直接修改?授權表:

    5.8.3.?從MySQL刪除用戶賬戶

    DROP USER user;




    posted @ 2008-04-29 13:52 G_G 閱讀(11673) | 評論 (3)編輯 收藏

    僅列出標題
    共16頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
    主站蜘蛛池模板: xxxxxx日本处大片免费看| 久久久国产精品亚洲一区| 免费人成年轻人电影| 国产精品久久久久久久久久免费| 亚洲成A人片777777| 中文字幕不卡亚洲 | 亚洲人成免费电影| 亚洲美女aⅴ久久久91| 亚洲大香人伊一本线| 亚洲精品第五页中文字幕| 亚洲天天做日日做天天欢毛片| 国产色爽女小说免费看| 日本特黄特色aa大片免费| 国产一区二区视频免费| 亚洲日韩VA无码中文字幕| 亚洲人成网亚洲欧洲无码久久| 两个人的视频高清在线观看免费| 中国一级特黄的片子免费 | 亚洲日韩精品无码一区二区三区| 国色精品卡一卡2卡3卡4卡免费| igao激情在线视频免费| 成人无码区免费A∨直播| 久久久久久国产a免费观看不卡| 久久久久se色偷偷亚洲精品av| 永久亚洲成a人片777777| 国产亚洲成AV人片在线观黄桃| 国产真实伦在线视频免费观看| 国产福利视精品永久免费 | 亚洲私人无码综合久久网| 国产亚洲福利在线视频| 美女黄网站人色视频免费| 一个人看的hd免费视频| 免费人成网站在线观看不卡| 国产精品久久永久免费| 国产精品国产免费无码专区不卡| 黄页网站免费观看| 免费人妻av无码专区| 亚洲Av无码专区国产乱码DVD| 亚洲av麻豆aⅴ无码电影| 亚洲成AV人片在线观看无码| 亚洲人成在线免费观看|