随笔-295  评论-26  文章-1  trackbacks-0
 

select userenv('language') from dual

Oracle/PLSQL: UserEnv Function


In Oracle/PLSQL, the userenv function can be used to retrieve information about the current Oracle session. Although this function still exists in Oracle for backwards compatibility, it is recommended that you use the sys_context function instead.

The syntax for the userenv function is:

userenv( parameter )

parameter is the value to return from the current Oracle session. The possible values are:

Parameter Explanation
CLIENT_INFO Returns user session information stored using the DBMS_APPLICATION_INFO package
ENTRYID Available auditing entry identifier
INSTANCE The identifier number of the current instance
ISDBA Returns TRUE if the user has DBA privileges. Otherwise, it will return FALSE.
LANG The ISO abbreviation for the language
LANGUAGE The language, territory, and character of the session. In the following format:
     language_territory.characterset
SESSIONID The identifier of the auditing session
TERMINAL The OS identifier of the current session

For example:

userenv('ENTRYID') would return FALSE
userenv('LANGUAGE') would return 'AMERICAN_AMERICA.WE8DEC'
posted @ 2007-08-24 11:31 华梦行 阅读(1196) | 评论 (0)编辑 收藏
     摘要: javaScript技巧集合 事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture();  eve...  阅读全文
posted @ 2007-08-24 11:13 华梦行 阅读(264) | 评论 (0)编辑 收藏

hibernate数据加载get/load的区别

关键字:   hibernate    

Session.load/get方法均可以根据指定的实体类和id从数据库读取记录,并返回与之对应的实体对象。其区别在于:

  1. 如果未能发现符合条件的记录,get方法返回null,而load方法会抛出一个ObjectNotFoundException。
  2. Load方法可返回实体的代理类实例,而get方法永远直接返回实体类。
  3. load方法可以充分利用内部缓存和二级缓存中的现有数据,而get方法则仅仅在内部缓存中进行数据查找,如没有发现对应数据,将越过二级缓存,直接调用SQL完成数据读取。

Session在加载实体对象时,将经过的过程:

  1. 首先,Hibernate中维持了两级缓存。第一级缓存由Session实例维护,其中保持了Session当前所有关联实体的数据,也称为内部缓存。而第二级缓存则存在于SessionFactory层次,由当前所有由本SessionFactory构造的Session实例共享。出于性能考虑,避免无谓的数据库访问,Session在调用数据库查询功能之前,会先在缓存中进行查询。首先在第一级缓存中,通过实体类型和id进行查找,如果第一级缓存查找命中,且数据状态合法,则直接返回。
  2. 之后,Session会在当前“NonExists”记录中进行查找,如果“NonExists”记录中存在同样的查询条件,则返回null。“NonExists”记录了当前Session实例在之前所有查询操作中,未能查询到有效数据的查询条件(相当于一个查询黑名单列表)。如此一来,如果Session中一个无效的查询条件重复出现,即可迅速作出判断,从而获得最佳的性能表现。
  3. 对于load方法而言,如果内部缓存中未发现有效数据,则查询第二级缓存,如果第二级缓存命中,则返回。
  4. 如在缓存中未发现有效数据,则发起数据库查询操作(Select SQL),如经过查询未发现对应记录,则将此次查询的信息在“NonExists”中加以记录,并返回null。
  5. 根据映射配置和Select SQL得到的ResultSet,创建对应的数据对象。
  6. 将其数据对象纳入当前Session实体管理容器(一级缓存)。
  7. 执行Interceptor.onLoad方法(如果有对应的Interceptor)。
  8. 将数据对象纳入二级缓存。
  9. 如果数据对象实现了LifeCycle接口,则调用数据对象的onLoad方法。
  10. 返回数据对象。
posted @ 2007-08-24 08:42 华梦行 阅读(82) | 评论 (0)编辑 收藏
public ITM_BuyContract getBuyContractById(String id) {
        ITM_BuyContract bc = null;
        Session session = HibernateUtil.getSession();
        bc = (ITM_BuyContract) session.get(ITM_BuyContract.class,id);
        return bc;
    }
posted @ 2007-08-23 15:39 华梦行 阅读(84) | 评论 (0)编辑 收藏

做webservice 尽量将具体的实现写在javabean里,这样可以减少客户网站和webservice的耦合,就是说你修改了具体的实现之后,客户网站并不需要重新部署,从而提高开发效率提高

posted @ 2007-08-23 14:56 华梦行 阅读(94) | 评论 (0)编辑 收藏
     摘要:   阅读全文
posted @ 2007-08-23 09:15 华梦行 阅读(17) | 评论 (0)编辑 收藏
function strLen(str) {
    if (!str) return 0;
    var len = 0;
    var pattern = /[\u4E00-\u9FA5]|[\uFE30-\uFFA0]/;
    for (var i = 0, j = str.length; i < j; i++) {
        if (pattern.test(str.charAt(i))) {
            len += 2;
        } else {
            len++;
        }
    }
    return len;
}
posted @ 2007-08-22 13:38 华梦行 阅读(152) | 评论 (0)编辑 收藏

/*
 * ViewUploadFile.java
 *
 * Created on 2006年2月4日, 上午1:29
 */

package path.system.manager;

import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;
import org.hibernate.Session;
import system.entity.CRM_UploadFile;
import.FileStorageService;

public class ViewUploadFile extends HttpServlet {
    private FileInputStream isFile = null;
   
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

        String szCoObject=request.getParameter("CoObject");
        String szID=request.getParameter("ID");
        String szMode = request.getParameter("Mode");
       
        //清空缓冲
        response.reset();
       
        OutputStream osOut = response.getOutputStream();
       
        if(szID == null || szID.equals("") || szID.equals("0"))
        {  
            byte[] cFileData = this.getNoDate (szCoObject);
           
            this.isFile.read(cFileData);
            osOut.write(cFileData);
        }
        else
        {
            Session ssSession = HibernateUtil.getSession();
            CRM_UploadFile csUpload;

            csUpload = (CRM_UploadFile)ssSession.load(CRM_UploadFile.class,Integer.valueOf(szID));

            String szFileName =csUpload.getFileName();
            if (szFileName==null) szFileName = "";
            String szRightName = new String( szFileName.getBytes(), "ISO8859_1" );      //中文文件名处理
            String szFileSize = csUpload.getFileSize().toString();
            String urlFileName = csUpload.getUrlFileName();
///输出到网页
            if ("0".equals(szFileSize)) {
                byte[] cFileData = this.getNoDate(szCoObject);
                this.isFile.read(cFileData);
                osOut.write(cFileData);
            } else {
                if(szMode.equals("Download")) {
                        response.setContentType("application/x-msdownload;");           //下载类型
                        response.setHeader("Content-Disposition","attachment; filename=" + szRightName);
                } else {
                        response.setContentType(csUpload.getContentType());
                        response.setHeader("Content-Disposition","filename=" + szRightName);
                }
                response.setHeader("content-length", szFileSize);
                //java.sql.Blob blob = csUpload.getBinaryData();
                File file = new File(FileStorageService.getRootPath() + urlFileName);
                if (!file.exists())
                    return;
               
                InputStream bis = new BufferedInputStream(new FileInputStream(file));
                byte[] buffer = new byte[2048];
                for (int i = bis.read(buffer); i > 0; i = bis.read(buffer))
                    osOut.write(buffer, 0, i);
                bis.close();
                   
            }
        }
       
        //防止超时
        //response.setStatus( response.SC_OK );
        response.flushBuffer();
    }
   
    private byte[] getNoDate (String szCoObject) throws IOException{
        String szFileName="";
        if(szCoObject.equals("Employee"))
            szFileName = getServletContext().getRealPath("/images/Employee/NoPhoto.gif");
        else
            szFileName = getServletContext().getRealPath("/images/Commodity/NoPhoto.gif");
        this.isFile= new FileInputStream(szFileName);

        int nSize = this.isFile.available();
        byte[] cFileData = new byte[nSize];
        return cFileData;
    }
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }
   
    /** Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}

posted @ 2007-08-21 13:24 华梦行 阅读(106) | 评论 (0)编辑 收藏
public final int read(byte[] b)
               throws IOException
从所包含的输入流中读取一定数量的字节,并将它们存储到缓冲区数组 b 中。以整数形式返回实际读取的字节数。在输入数据可用、检测到文件末尾 (end of file) 或抛出异常之前,此方法将一直阻塞。

如果 b 为 null,则抛出 NullPointerException。如果 b 的长度为零,则不读取字节并返回 0;否则试图读取至少一个字节。如果因为该流在文件末尾而无字节可用,则返回值 -1;否则至少读取一个字节并将其存储到 b 中。

将读取的第一个字节存储到元素 b[0] 中,将下一个字节存储到 b[1] 中,依此类推。读取的字节数至多等于 b 的长度。设 k 为实际读取的字节数;这些字节将存储在从 b[0]b[k-1] 的元素中,b[k]b[b.length-1] 的元素不受影响。

如果因为文件末尾以外的其他原因而无法读取第一个字节,则抛出 IOException。尤其在输入流已关闭的情况下,将抛出 IOException

read(b) 方法与以下方法的效果相同:

 read(b, 0, b.length) 
posted @ 2007-08-21 12:43 华梦行 阅读(8147) | 评论 (0)编辑 收藏

import java.io.*;
import java.net.*;
public class Test {
    public boolean saveUrlAs(String photoUrl, String fileName) {
        //此方法只能用于HTTP协议
        try {
            URL url = new URL(photoUrl);
            HttpURLConnection connection = (HttpURLConnection) url.
                    openConnection();
            DataInputStream in = new DataInputStream(connection.getInputStream());
            DataOutputStream out = new DataOutputStream(new FileOutputStream(fileName));
            byte[] buffer = new byte[4096];
            int count = 0;
            while ((count = in.read(buffer)) > 0) {
                out.write(buffer, 0, count);
            }
            out.close();
            in.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
   
    public String getDocumentAt(String urlString) {
        //此方法兼容HTTP和FTP协议
        StringBuffer document = new StringBuffer();
        try {
            URL url = new URL(urlString);
            URLConnection conn = url.openConnection();
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                document.append(line + "\n");
            }
            reader.close();
        }catch (MalformedURLException e) {
            System.out.println("Unable to connect to URL: " + urlString);
        }catch (IOException e) {
            System.out.println("IOException when connecting to URL: " +
                    urlString);
        }
        return document.toString();
    }
   
    public static void main(String[] args) throws IOException {
        Test test = new Test();
        String photoUrl = "http://www.cjsdn.net/index.html";
        String fileName = photoUrl.substring(photoUrl.lastIndexOf("/"));
        String filePath = "c:";
        boolean flag = test.saveUrlAs(photoUrl, filePath + fileName);
        System.out.println("Run ok!\nGet URL file " + flag);
    }
}


 

posted @ 2007-08-21 11:30 华梦行 阅读(909) | 评论 (0)编辑 收藏

import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/*
 * hello.java
 *
 * Created on 2007年8月3日, 上午11:15
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author ljl
 */
public class hello {
   
    /** Creates a new instance of hello */
    public hello() {
    }
    public static void main(String s[]) throws Exception{
        String sss="Sogood";
       // System.out.print(sss.substring(0,4));
        ReadURL("http://java.ok6.org/logo.jpg");
    }
    public static void ReadURL(String URLName) throws Exception // 如果发生异常则向上抛出
    {
        int HttpResult; // 服务器返回的状态
        URL url =new URL(URLName); // 创建URL
       
        URLConnection urlconn = url.openConnection(); // 试图连接并取得返回状态码
        urlconn.connect();
        HttpURLConnection httpconn =(HttpURLConnection)urlconn;
        HttpResult = httpconn.getResponseCode();
        System.out.println(HttpResult);
        if(HttpResult != HttpURLConnection.HTTP_OK) // 不等于HTTP_OK说明连接不成功
           System.out.print("fail");
        else {
            int filesize = urlconn.getContentLength(); // 取数据长度
            System.out.println(filesize);
            InputStreamReader isReader = new InputStreamReader(urlconn.getInputStream());
            char[] buffer = new char[2048]; // 创建存放输入流的缓冲
            int num = 0; // 读入的字节数
            while(num>-1) {
                num = isReader.read(buffer); // 读入到缓冲区
                if(num < 0) break; // 已经读完
                System.out.print("suc");
              System.out.println(new String(buffer,0,num)); // 显示出来
            }
            isReader.close();//关闭输入流
        }
    }
   
   
}

posted @ 2007-08-21 10:38 华梦行 阅读(976) | 评论 (0)编辑 收藏

404:服务器找不到指定的资源,请求的网页不存在(譬如浏览器请求的网页被删除或者移位,但不排除日后该链接有效的可能性);32C站长资讯
410:请求的网页不存在(注意:410表示永久性,而404表示临时性);32C站长资讯
200:服务器成功返回请求的网页;32C站长资讯
301:网址永久性重定向32C站长资讯
302:网址临时性重定向

posted @ 2007-08-21 10:31 华梦行 阅读(212) | 评论 (0)编辑 收藏
试一试修改server.xml文件,路径在:
server\default\deploy\jbossweb-tomcat55.sar

在host标签中增加
<Context cookies="true" crossContext="true" path="/test" docBase="z:\test" />



请问一下,我们在tomcat中的server.xml中每设置一个<Context...../>比如:
<Context path="/oa" docBase="oa" debug="4" reloadable="true" crossContext="true"> </Context>
相应的工程中的.java文件修改了,可以自动重新加载。。。
其他工程修改就不行,,又要再加一条相应的语句,,不知道有没有其他的方法只要设置一下,就会侦听所有的工程,,,任何一个工程修改,,都可以自动重新加载。。。谢谢。。
我用的是myeclipse+eclipse+tomcat

posted @ 2007-08-21 09:48 华梦行 阅读(435) | 评论 (0)编辑 收藏
Singleton 模式主要作用是保证在 Java 应用程序中,一个类 Class 只有一个实例存在。

  一般 Singleton 模式通常有几种种形式:

  第一种形式:定义一个类,它的构造函数为 private 的,它有一个 static private 的该类变量,在类初始化时实例话,通过一个 public getInstance 方法获取对它的引用 , 继而调用其中的方法。

public class Singleton {

   private Singleton(){}

   // 在自己内部定义自己一个实例,是不是很奇怪?

   // 注意这是 private 只供内部调用

   private static Singleton instance = new Singleton();

   // 这里提供了一个供外部访问本 class 的静态方法,可以直接访问  

   public static Singleton getInstance() {

     return instance;   

   }

}

 

  第二种形式:

public class Singleton {

   private static Singleton instance = null;

   public static synchronized Singleton getInstance() {

   // 这个方法比上面有所改进,不用每次都进行生成对象,只是第一次     

   // 使用时生成实例,提高了效率!

   if (instance==null)

     instance new Singleton();

return instance;    }

}

posted @ 2007-08-20 14:01 华梦行 阅读(559) | 评论 (0)编辑 收藏
swtich 是否能作用在 byte 上,是否能作用在 long 上,是否能作用在 String ?

   switch expr1 )中, expr1 是一个整数表达式。因此传递给 switch case 语句的参数应该是 int short char 或者 byte long,string 都不能作用于 swtich

posted @ 2007-08-20 13:52 华梦行 阅读(3291) | 评论 (0)编辑 收藏
try {} 里有一个 return 语句,那么紧跟在这个 try 后的 finally {} 里的 code 会不会被执行,什么时候被执行,在 return 前还是后 ?

  会执行,在 return 前执行。

posted @ 2007-08-20 13:45 华梦行 阅读(177) | 评论 (0)编辑 收藏
Overload Override 的区别。 Overloaded 的方法是否可以改变返回值的类型 ?

  方法的重写 Overriding 和重载 Overloading Java 多态性的不同表现。重写 Overriding 是父类与子类之间多态性的一种表现,重载 Overloading 是一个类中多态性的一种表现。如果在子类中定义某方法与其父类有相同的名称和参数,我们说该方法被重写 (Overriding) 。子类的对象使用这个方法时,将调用子类中的定义,对它而言,父类中的定义如同被“屏蔽”了。如果在一个类中定义了多个同名的方法,它们或有不同的参数个数或有不同的参数类型,则称为方法的重载 (Overloading) Overloaded 的方法是可以改变返回值的类型

posted @ 2007-08-20 13:40 华梦行 阅读(229) | 评论 (0)编辑 收藏
数组有没有 length() 这个方法 ? String 有没有 length() 这个方法?

  数组没有 length() 这个方法,有 length 的属性。

   String 有有 length() 这个方法。

posted @ 2007-08-20 13:39 华梦行 阅读(1898) | 评论 (0)编辑 收藏
sleep:在睡觉,要睡够了你才叫得醒
wait:在等你叫它
TOP
回复人:Polarislee(北极星)(灌水是我无言的抗议)  一星(中级)  信誉:110      2005-3-1 13:35:27  得分:20

sleep是Thread类的静态方法。sleep的作用是让线程休眠制定的时间,在时间到达时恢复,也就是说sleep将在接到时间到达事件事恢复线程执行,例如:

try{
System.out.println("I'm going to bed");
Thread.sleep(1000);
System.out.println("I wake up");
}
catch(IntrruptedException e) {
}


wait是Object的方法,也就是说可以对任意一个对象调用wait方法,调用wait方法将会将调用者的线程挂起,直到其他线程调用同一个对象的notify方法才会重新激活调用者,例如:


//Thread 1

try{
obj.wait();//suspend thread until obj.notify() is called
}
catch(InterrputedException e) {
}
posted @ 2007-08-20 13:23 华梦行 阅读(536) | 评论 (0)编辑 收藏

16 Collection Collections 的区别。

   Collections 是个 java.util 下的类,它包含有各种有关集合操作的静态方法。

   Collection 是个 java.util 下的接口,它是各种集合结构的父接口。

posted @ 2007-08-20 13:17 华梦行 阅读(145) | 评论 (0)编辑 收藏
仅列出标题
共15页: First 上一页 7 8 9 10 11 12 13 14 15 下一页