Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

PostgreSQL/Oracle Table

ͨ³£ÎÒ們ÔÚ½¨Á¢ PostgreSQL/Oracle 資ÁÏ庫µÄ時ºò, Èç¹ûҪʹÓà MySQL/MS-SQL identity À×ͬµÄ¹¦ÄÜ, ¾ÍÊÇÒª採Óà Sequence 來½¨Á¢, ¶ø為ÁËÿһ個 Table ¶¼ÓÐ獨Á¢µÄÐò號產ÉúÆ÷, ÎÒ們會½¨Á¢個別µÄ sequence.
ÀýÈç (PostgreSQL sample):
CREATE SEQUENCE "student_seq" start 1 increment 1 maxvalue 2147483647 minvalue 1  cache 1;
create table student (
      id bigint PRIMARY KEY DEFAULT NEXTVAL('student_seq'),
      name character varying(50),
      studentno character varying(50)
)
當ÎÒ們ʹÓûù±¾µÄ SQL command ¾ÍÊÇ
Insert into student ( name, studentno ) values ( 'jini', '890099' )
進ÐÐ Insert µÄ動×÷, Ëû×ÔÈ»會幫ÎÒÈ¡µÃ nextval of student_seq 進ÐÐ Insert.
ÄÇ麼, ÔÚ Hibernate annotation 標準µÄ×÷·¨, ¾ÍÊÇ
@Entity
@SequenceGeneratorr(name = "TheSEQ", allocationSize = 1, initialValue = 0, sequenceName = "student_seq")
public class Student implements Serializable {
       @Id
       @GeneratedValue(strategy = GenerationType.SEQUENCE
, generator = "TheSEQ")
       private Long id;
       // other attributes, getters and setters
}
這樣, ÎÒÿһ個 @Id ¶¼µÃ»¨時間寫Ö¸¶¨µÄ sequence name,
雖È»沒ÓÐʲ麼²»ºÃ, µ«ÊÇÎÒ們¿ÉÒÔÀûÓà [tablename]_seq µÄÔ­則¶¨義 seq, ¾Í應該¿ÉÒÔ͸過 Dialect 來決¶¨ÎÒµÄ IdGenerator µÄ·½Ê½
ËùÒÔÎÒÏ£Íûδ來µÄ³Ìʽ碼Ö»ÓÐÒÔÏÂËùÁÐ, ÀûÓà AUTO ¶ø·Ç SEQUENCE generated type.
@Entity
public class Student implements Serializable {
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private


Ïà¹ØÎĵµ£º

jdbcÁ¬½ÓOracle

      ËäȻѧϰJavaºÜ¾ÃÁË£¬×Ô¼ºÒ²Á¬½Ó¹ýһЩÊý¾Ý¿â£¬±ÈÈçmysqlÖ®ÀàµÄ£¬Èç½ñÄØ£¬Ò²Ñ§Ï°ÁËÒ»¶Îʱ¼äµÄOracle£¬È»¶øÄØ£¬½ñÌìÊÇÎÒµÚÒ»´ÎÁ¬½ÓOracle£¬ºÙºÙ£¬Ó¦¸Ã»¹²»ËãÌ«³Ù°É¡£
    ½ñÌìÄØ£¬Óе㱿׾£¬´ó¼ÒĪЦ£¡
    ÎÒÕâÊÇÒ»¸ö²éѯÀý×Ó
    Ê×ÏÈ£¬Ô ......

Oracle¸ß¼¶¸´ÖÆ

 ÔÚ¿ªÊ¼Ö®Ç°£¬ÐèÒª¼òµ¥ËµÃ÷һϣ¬Ä¿Ç°¹«Ë¾Óм¸¸öÏîÄ¿¶¼²ÉÓÃOracle×÷ΪÊý¾Ý¿âƽ̨£¬²¢ÇÒÓеÄÏîĿʹÓõ½ÁËOracleµÄÊý¾Ý¿â¸´ÖƼ¼Êõ£¬ÆäÖÐÒ²Óöµ½ÁËһЩÎÊÌ⣬Òò´ËÔÚÕâÀÎÒ¶ÔOracleµÄ¸´ÖƼ¼Êõ̸һÏÂÎÒ¸öÈ˵ÄÀí½â£¬Ï£ÍûÄܹ»¶Ô²ÉÓÃOracleÊý¾Ý¿âµÄÏîÄ¿×éÓÐËù°ïÖú¡£ÆäÖÐÔÚÎÄÖÐʹÓõ½µÄSQL½Å±¾¶¼ÊǾ­¹ý¼ìÑé¿ÉÒÔÔËÐеġ£
¡¡¡¡Ê ......

oracle²åÈëʱÈçºÎ²åÈëuuId

 ÊÇÏëÉú³ÉGUIDÂð£¿
SQL> select   sys_guid() from dual ;
SYS_GUID()
--------------------------------
F18031C69D8345DEB305D4B2E796A282
Äã¿ÉÒ԰ѱíµÄÖ÷¼ü×ֶεÄȱʡֵÉèΪsys_guid()
insert into luxian_info (id) values(sys_guid()); ......

Oracle ³£ÓÃsqlplusÃüÁî

 
Ò»¡¢ORACLEµÄÆô¶¯ºÍ¹Ø±Õ
1¡¢ÔÚµ¥»ú»·¾³ÏÂÒªÏëÆô¶¯»ò¹Ø±ÕORACLEϵͳ±ØÐëÊ×ÏÈÇл»µ½ORACLEÓû§£¬ÈçÏÂ
su - oracle
a¡¢Æô¶¯ORACLEϵͳ
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>startup
SVRMGR>quit
b¡¢¹Ø±ÕORACLEϵͳ
oracle>svrmgrl
SVRMGR>connect internal
SVRMGR>shutdow ......

Oracle×Ô´úµÄÏ̳߳Ø

µÚÒ»¸öÀࣺ
/**
 *
 * ´æ·ÅoracleÊý¾Ý¿âµÄÁ´½ÓÐÅÏ¢¡£
 *
 * @author ZhongHuiQiang
 *
 */
public interface IOracleDAOInfor {
 String DB_SERVER_HOSET = "localhost";
 String DB_SERVER_NAME = "ppoo";
 String DB_USER_NAME = "system";
 String DB ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ