×

Loading...
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!
Ad by
  • 技多不压身,工到自然成:安省技工证书特训班,点击咨询报名!

还有一个问题请教你,关于JSP 和JAVA 数据库连接的问题,不知道你有没有接触过?

症状:
在我的测试程序中,我是使用Oracle的JDBC驱动程序连接ORACLE 数据库。

在JSP 有一行代码是这样的;
//装载 ORACLE JDBC 驱动程序
java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

如果按这种以上的方式来连接数据库是没有问题。

现在我不想在JSP 中写这样的语句访问数据库,改用JAVA BEAN的写法。
我在JAVA 程序中,写个DB 类
那么我必须在程序开头的时候必须声明类库文件,也就是必须有以下一行。
import oracle.jdbc.driver.*;
但是这样写,在编译的时候通不过,原因是编译器没办法找到包。

问题:
1:为什么在JSP 调用的时候就没有这个问题,我是使用WEBLOGIC 做为
WEB 服务器,WEBLOGIC 在编译JSP 文件的时候,是怎么找到这个包的?
我装完WEBLOGIC 后,并没有对它进行特殊的设置。

2:用 J2SDK 写的时候,如何把这个包正确的引入?我找不到这个包,不知道它藏在哪里?
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 熟悉ORACLE 的DX 过来 看一下
    ORACLE 数据库表中有中文字符,用SQL PLUS 查询的时候,没法显示中文,该怎么解决。我是在中文2000 PROFESSIONAL 下的装的英文版的ORACLE ,版本号是8.17.

    A B
    ---------- ----------
    1 111
    2 222
    3 333
    4 ?
    4 ?
    4 ?
    4 ?
    以上是查询时的结果,其中?是中文字符没法显示的结果。
    • 改字符集试试,hkey_local_machine/software/oracle->nls_lang: SIMPLIFIED CHINESE_CHINA.ZHS16GBK
      • 试过了,不行
    • If you have not set the character set or national character set as Simplified Chinese when creating database,you cannot store Chinese character in the database.
      • when I create a database, the system doesn't give me any tips about setting character.I use Database Configuration Assistant to create a database.
    • 不懂ORACLE. 但以前用DB2英文版可以支持中文, 就是所谓的GARBAGE IN, GARBAGE OUT. 只要插入和读出用相同的中文系统即可.
    • 既然你肯定中文已经在ORACLE里面了,那没法显示会不会是SQL NET的问题?
      • 我不能确定。不单是SQL NET 显示的问题,我直接在系统添加中文的记录,但添加进去的是乱码。我不知道,英文的ORACLE 是否能够支持中文,如果能支持,该怎么设置?
    • My suggestion is to try it out using browser,
      but you need a servlet engine and write a JSP with JDBC to connect to your oracle. and select it out and present it in browser.
      • I have already tried it by using JSP , same result.
        http://65.95.181.130/test.jsp
        • Maybe the data is corrupted, because
          How did you load the Chinese data ?
          If you are using a web browser to input Chinese Chars, it will be OK when you fetch them. However if you using MS word or other editors,
          and using command line to insert the data. it's very likely the data is corrupted
    • 请进。。
      无论你的ORACLE CS如何,(即使为US7ASCII),只要server side and client CS is same, then you should be OK for chinese char.

      check server side:
      select * from v$nls_parameters where parameter ='NLS_CHARACTERSET'

      then before run SQL*PLUS, set env varible
      NLS_LANG=x_y.z to the same as server side.

      Then everything will be OK.

      some tip about CS:
      select dump(<column>) from <tab>;
      • client and server are in the same computer, I don't know where to set NLS_LANG, is it in regedit or other place. by the way, I have run sql statement as you say , the result is WE8ISO8859P1.
        • under cmd.exe C:> input commands: 1) set NLS_LANG=AMERICAN_AMERICA.WE8ISO8858P1 2) sqlplus u/p@sid
    • 查询视图nls_database_parameters 看database characterset 和 national characterset是否支持中文,若不支持重新创建数据库,选定制创建,其中有选字符集选项,选ZHS16GBK或其它类似ZHXXGBXX的
    • 问题解决了,几个步骤就可以了。
      1、检查操作系统级Oracle汉字显示的字符集:运行regedit,定位到:
      HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE
      找到以下字符串
      NLS_LANG

      检查是否以下内容,如不是,改之
      SIMPLIFIED CHINESE_CHINA.ZHS16GBK

      2、
      进入SQL*PLUS
      connect internal
      update props$ set value$='ZHS16GBK
      ' where name='NLS_CHARACTERSET';
      commit;
      alter database ORCL character set ZHS16GBK;
      alter database ORCL national character set ZHS16GBK;
      commit;
      • stop doing this on production database!!!! this may corrupt database. to change character set, you need following oracle document instead of modifying core table directly.
    • 来晚了,too easy.
      • 还有一个问题请教你,关于JSP 和JAVA 数据库连接的问题,不知道你有没有接触过?
        症状:
        在我的测试程序中,我是使用Oracle的JDBC驱动程序连接ORACLE 数据库。

        在JSP 有一行代码是这样的;
        //装载 ORACLE JDBC 驱动程序
        java.sql.DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

        如果按这种以上的方式来连接数据库是没有问题。

        现在我不想在JSP 中写这样的语句访问数据库,改用JAVA BEAN的写法。
        我在JAVA 程序中,写个DB 类
        那么我必须在程序开头的时候必须声明类库文件,也就是必须有以下一行。
        import oracle.jdbc.driver.*;
        但是这样写,在编译的时候通不过,原因是编译器没办法找到包。

        问题:
        1:为什么在JSP 调用的时候就没有这个问题,我是使用WEBLOGIC 做为
        WEB 服务器,WEBLOGIC 在编译JSP 文件的时候,是怎么找到这个包的?
        我装完WEBLOGIC 后,并没有对它进行特殊的设置。

        2:用 J2SDK 写的时候,如何把这个包正确的引入?我找不到这个包,不知道它藏在哪里?
        • 1.you need set the classpath: weblogic.jar, where weblogic sets it as default. it is in weblogic_root/lib directory. 2. you can download the driver, then set it in your application.
          search "oracle" "classes12.zip" to know where you can get it.
          • 谢谢!ROLIA 上高手真不少,都找到专业工作了没有?