收獲每一天

          -----在JAVA的路上越走越遠!
          posts - 6, comments - 0, trackbacks - 0, articles - 2
            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

          2007年2月17日

          一年又一年,又一年過去了!

          posted @ 2007-02-17 23:04 喜悅天天收獲 閱讀(95) | 評論 (0)編輯 收藏

          2006年5月4日

          數(shù)據(jù)庫要求
          1、建立一個表code_dam,包含以下字段
          ?? id int,自增,主鍵
          ?? code nvarchar(20), not null? (大壩編號)
          ?? name nvarchar(20), not null? (大壩名稱)
          ?? remark nvarchar(200)???????? (備注)
          2、編程實現(xiàn)對表code_dam的增刪改查功能,包括:
          ?? 添加大壩編碼(添加一條記錄到數(shù)據(jù)庫,要求:大壩編號不能重復,大壩名稱不能重復)
          ?? 修改大壩編碼(要求:大壩編號不能重復,大壩名稱不能重復)
          ?? 刪除一個大壩編碼
          ?? 大壩編碼列表(code_dam表中所有的記錄,使用列表將其他功能串在一起)
          ?? 查看大壩編碼(顯示指定id的大壩編號、名稱、備注)



          //建立數(shù)據(jù)庫

          -- Create table
          create table CODE_DAM
          (
          ? ID???? INTEGER not null,
          ? CODE?? VARCHAR2(20) not null,
          ? NAME?? VARCHAR2(20) not null,
          ? REMARK VARCHAR2(200)
          )
          tablespace DAM
          ? pctfree 10
          ? initrans 1
          ? maxtrans 255
          ? storage
          ? (
          ??? initial 64K
          ??? minextents 1
          ??? maxextents unlimited
          ? );
          -- Add comments to the table
          comment on table CODE_DAM
          ? is '大壩管理';
          -- Add comments to the columns
          comment on column CODE_DAM.CODE
          ? is '大壩編號';
          comment on column CODE_DAM.NAME
          ? is '大壩名稱';
          -- Create/Recreate primary, unique and foreign key constraints
          alter table CODE_DAM
          ? add constraint ID primary key (ID)
          ? using index
          ? tablespace DAM
          ? pctfree 10
          ? initrans 2
          ? maxtrans 255
          ? storage
          ? (
          ??? initial 64K
          ??? minextents 1
          ??? maxextents unlimited
          ? );

          //自增解決辦法
          //序列
          -- Create sequence
          create sequence SEQ_CODE_DAM
          minvalue 1
          maxvalue 999999999999999999999999999
          start with 31
          increment by 1
          cache 10;
          //觸發(fā)器
          CREATE OR REPLACE TRIGGER TRG_code_dam
          BEFORE
          INSERT? ON code_dam
          FOR EACH ROW
          begin
          SELECT SEQ_code_dam.NEXTVAL
          INTO:NEW.id
          FROM DUAL;
          End TRG_code_dam;

          ?

          //相關存儲過程

          //查詢所有數(shù)據(jù)
          //包
          create or replace package showall is
          type mycursor is ref cursor;
          procedure GetRecords(ret_cursor out mycursor);
          end showall;
          //包體
          create or replace package body showall is
          procedure GetRecords(ret_cursor out mycursor) as
          begin
          open ret_cursor for select * from code_dam;
          end GetRecords;
          end showall;


          //刪除數(shù)據(jù)
          create or replace procedure delRecord(id_in in int)
          is
          begin
          delete from code_dam where id=id_in;
          commit;
          end;

          //插入數(shù)據(jù)
          create or replace procedure insertRecord(code_in in varchar2,name_in in varchar2,remark_in in varchar2) is
          begin
          insert into code_dam (code,name,remark) values (code_in,name_in,remark_in);
          commit;
          end;


          //更新數(shù)據(jù)
          create or replace procedure updataRecord(id_in in int,code_in in varchar2,name_in in varchar2,remark_in in varchar2)
          is
          begin
          update code_dam set code=code_in,name=name_in,remark=remark_in where id=id_in;
          commit;
          end;


          //檢查重復
          create or replace procedure checkdam
          (code_in in varchar2,name_in in varchar,name_out out varchar2)
          is
          begin
          select name into name_out from code_dam where code = code_in or name = name_in;
          end checkdam;


          //查詢單個數(shù)據(jù)
          //包
          create or replace package showdam is
          type mycursor is ref cursor;
          procedure GetRecords(id_in in int,ret_cursor out mycursor);
          end showdam;
          //包體
          create or replace package body showdam is
          procedure GetRecords(id_in in int,ret_cursor out mycursor) as
          begin
          open ret_cursor for select * from code_dam where id = id_in;
          end GetRecords;
          end showdam;

          posted @ 2006-05-04 21:51 喜悅天天收獲 閱讀(1302) | 評論 (0)編輯 收藏

          系統(tǒng)環(huán)境:
          1、操作系統(tǒng):Windows 2000
          2、數(shù)據(jù)庫: Oracle 8i R2 (8.1.6) for NT 企業(yè)版
          3、安裝路徑:C:\ORACLE

          說明:

          默認安裝完Oracle后,初學者應該了解的一些SQL語句

          1、連接
          SQL*Plus system/manager

          2、顯示當前連接用戶
          SQL> show user

          3、查看系統(tǒng)擁有哪些用戶
          SQL> select * from all_users;

          4、新建用戶并授權(quán)
          SQL> create user a identified by a;(默認建在SYSTEM表空間下)
          SQL> grant connect,resource to a;

          5、連接到新用戶
          SQL> conn a/a

          6、查詢當前用戶下所有對象
          SQL> select * from tab;

          7、建立第一個表
          SQL> create table a(a number);

          8、查詢表結(jié)構(gòu)
          SQL> desc a

          9、插入新記錄
          SQL> insert into a values(1);

          10、查詢記錄
          SQL> select * from a;

          11、更改記錄
          SQL> update a set a=2;

          12、刪除記錄
          SQL> delete from a;

          13、回滾
          SQL> roll;
          SQL> rollback;

          14、提交
          SQL> commit;


          ?
          軟件環(huán)境:
          1、Windows 98 第二版
          2、Oracle數(shù)據(jù)庫版本為:Personal Oracle7 Release 7.3.4.0.0
          3、Oracle安裝路徑為:C:\ORAWIN95

          命令列表:
          假設當前執(zhí)行命令為:select * from tab;

          (a)ppend     添加文本到緩沖區(qū)當前行尾    a? order by tname 結(jié)果:select * from tab order by tname;
                                                (注:a后面跟2個空格)
          (c)hange/old/new 在當前行用新的文本替換舊的文本 c/*/tname     結(jié)果:select tname from tab;
          (c)hange/text  從當前行刪除文本        c/tab       結(jié)果:select tname from ;
          del       刪除當前行
          del n      刪除第n行
          (i)nput 文本   在當前行之后添加一行
          (l)ist      顯示緩沖區(qū)中所有行
          (l)ist n     顯示緩沖區(qū)中第 n 行
          (l)ist m n    顯示緩沖區(qū)中 m 到 n 行
          run       執(zhí)行當前緩沖區(qū)的命令
          /        執(zhí)行當前緩沖區(qū)的命令
          r        執(zhí)行當前緩沖區(qū)的命令
          @文件名     運行調(diào)入內(nèi)存的sql文件,如:

          SQL> edit s<回車>
          如果當前目錄下不存在s.sql文件,則系統(tǒng)自動生成s.sql文件,
          在其中輸入“select * from tab;”,存盤退出。

          SQL> @s<回車>
          系統(tǒng)會自動查詢當前用戶下的所有表、視圖、同義詞。

          @@文件名     在.sql文件中調(diào)用令一個.sql文件時使用

          save 文件名   將緩沖區(qū)的命令以文件方式存盤,缺省文件擴展名為.sql
          get 文件名    調(diào)入存盤的sql文件
          start 文件名   運行調(diào)入內(nèi)存的sql文件

          spool 文件名   把這之后的各種操作及執(zhí)行結(jié)果“假脫機”即存盤到磁盤文件上,默認文件擴展名為.lst
          spool      顯示當前的“假脫機”狀態(tài)
          spool off    停止輸出

          例:
          SQL> spool a
          SQL> spool
          正假脫機到 A.LST
          SQL> spool off
          SQL> spool
          當前無假脫機


          exit       退出SQL*PLUS
          desc 表名    顯示表的結(jié)構(gòu)
          show user    顯示當前連接用戶
          show error    顯示錯誤
          show all     顯示所有68個系統(tǒng)變量值
          edit       打開默認編輯器,Windows系統(tǒng)中默認是notepad.exe,把緩沖區(qū)中最后一條SQL語句調(diào)入afiedt.buf文件中進行編輯
          edit 文件名   把當前目錄中指定的.sql文件調(diào)入編輯器進行編輯

          clear screen   清空當前屏幕顯示

          posted @ 2006-05-04 21:45 喜悅天天收獲 閱讀(478) | 評論 (0)編輯 收藏

          Java連接數(shù)據(jù)庫實例


          此文中的代碼主要列出連接數(shù)據(jù)庫的關鍵代碼,其他訪問數(shù)據(jù)庫代碼省略

          1、Oracle8/8i/9i數(shù)據(jù)庫(thin模式)
          Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
          String url="jdbc:oracle:thin:@localhost:1521:orcl";
          //orcl為數(shù)據(jù)庫的SID
          String user="test";
          String password="test";
          Connection conn= DriverManager.getConnection(url,user,password);

          2、DB2數(shù)據(jù)庫
          Class.forName("com.ibm.db2.jdbc.app.DB2Driver ").newInstance();
          String url="jdbc:db2://localhost:5000/sample";
          //sample為你的數(shù)據(jù)庫名
          String user="admin";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);

          3、Sql Server7.0/2000數(shù)據(jù)庫
          Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
          String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mydb";
          //mydb為數(shù)據(jù)庫
          String user="sa";
          String password="";
          Connection conn= DriverManager.getConnection(url,user,password);

          4、Sybase數(shù)據(jù)庫
          Class.forName("com.sybase.jdbc.SybDriver").newInstance();
          String url =" jdbc:sybase:Tds:localhost:5007/myDB";
          //myDB為你的數(shù)據(jù)庫名
          Properties sysProps = System.getProperties();
          SysProps.put("user","userid");
          SysProps.put("password","user_password");
          Connection conn= DriverManager.getConnection(url, SysProps);

          5、Informix數(shù)據(jù)庫
          Class.forName("com.informix.jdbc.IfxDriver").newInstance();
          String url =
          "jdbc:informix-sqli://123.45.67.89:1533/myDB:INFORMIXSERVER=myserver;
          user=testuser;password=testpassword";
          //myDB為數(shù)據(jù)庫名
          Connection conn= DriverManager.getConnection(url);

          6、MySQL數(shù)據(jù)庫
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1"
          //myDB為數(shù)據(jù)庫名
          Connection conn= DriverManager.getConnection(url);

          7、PostgreSQL數(shù)據(jù)庫
          Class.forName("org.postgresql.Driver").newInstance();
          String url ="jdbc:postgresql://localhost/myDB"
          //myDB為數(shù)據(jù)庫名
          String user="myuser";
          String password="mypassword";
          Connection conn= DriverManager.getConnection(url,user,password);

          posted @ 2006-05-04 17:50 喜悅天天收獲 閱讀(234) | 評論 (0)編輯 收藏

          2006年3月29日

          首先安裝JDK1.5
          然后右鍵“我的電腦”“屬性”
          選擇 “高級”
          點擊“環(huán)境變量”
          在“系統(tǒng)變量”中修改“path”變量,在后面加入“;c:/java/bin”其中c:/java為你裝的JDk的路徑。
          在“系統(tǒng)變量”中添加“CLASSPATH”變量,在后面加入“c:/java/lib/tools.jar;c:/java/lib/dt.jar;.”
          然后確定。
          JDK環(huán)境變量設置完
          最后裝上tomcat


          在tomcat的安裝目錄下找到“conf”文件夾。打開里面的文件“server.XMl”在文件尾部的

          ????? </Host>

          ??? </Engine>

          ? </Service>

          </Server>


          之前加入一行“<Context path="/web" docBase="web" debug="0" reloadable="true">”代碼

          其中: path=? 表示文件的web訪問路徑,docBase=? 表示網(wǎng)站文件的存放路徑。如上所示表示docBase="web"是指存放在tomcat安裝目錄下的webapps目錄下的web文件夾下。訪問路徑是http://localhost:8080/web

          如果你的網(wǎng)站文件存放路徑不在tomcat安裝目錄下的webapps目錄下,則要寫上全部路徑,例如:“docBase="d:/web"”

          posted @ 2006-03-29 18:07 喜悅天天收獲 閱讀(322) | 評論 (0)編輯 收藏

          2006年3月23日

          字符串變大寫或小寫的方法
          String text="ABCdef";
          text=text.toLowerCase();//字符串變小寫
          text=text.toUpperCase();//字符串變大寫

          字符大寫,小寫的方法:
          char ch="A";
          ch=Character.toLowerCase(ch);//字符變小寫
          ch=Character.toUpperCase(ch);//字符變大寫

          boolean b=Character.isLowerCase(ch);//判斷字符ch是否小寫
          boolean b=Character.isUpperCase(ch);//判斷字符ch是否大寫
          boolean b=Character.isLetter(ch);//判斷字符ch是否字符
          boolean b=Character.isDigit(ch);//判斷字符ch是否0-9的數(shù)字

          posted @ 2006-03-23 11:55 喜悅天天收獲 閱讀(1093) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 华池县| 方山县| 丰宁| 石渠县| 大悟县| 左云县| 共和县| 彰化县| 霍山县| 嵩明县| 务川| 屯留县| 黑龙江省| 永泰县| 平远县| 天峨县| 潢川县| 南部县| 旌德县| 达拉特旗| 大庆市| 手游| 开阳县| 盐源县| 赤城县| 格尔木市| 栾川县| 昔阳县| 乐业县| 运城市| 宁远县| 连南| 永顺县| 江北区| 哈尔滨市| 桓台县| 连州市| 安西县| 凉山| 北辰区| 吉木乃县|