3月21日——培訓第85天

 昨天的程序中還可以考慮添加菜單項,

關鍵代碼(打開文件):

String filePath = "";
    File file = null;
    BufferedReader br;
    String content = "";
   
    public void jMenuItem2_actionPerformed(ActionEvent e) {
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
           file = fileChooser.getSelectedFile();
           filePath = file.getAbsolutePath();
           //JOptionPane.showMessageDialog(this,"file:" + filePath);
           try {
             br = new BufferedReader(new FileReader(file));
             content = br.readLine();
             while (content != null){
                 text.append(content + "/n");
                 content = br.readLine();
             }
           }catch(Exception ee){
               ee.printStackTrace();
           }
        
          
        }
    }

 

-----------------------------------------------------------
每個測試方法先調用@Before,然後調用測試方法@Test,再調用@After,
也就是說@Before和@After是每個測試方法都必須調用的!
其實就是那個SetUp和TearDown方法,只不過由於版本的不同導致稱呼不同而已……

有一個@BeforeClass只調用一次

一個簡單的測試示例如下:

package com.test;

import org.junit.*;
import static org.junit.Assert.*;

public class H1Test
{
 @Before
  public void m1()
 {
  System.out.println("before");
 }

 @Test
  public void t1()
 {
  System.out.println("1");
  assertEquals((1+1),2);
 }

 @Test
  public void t2()
 {
  System.out.println("2");
  assertEquals((1+2),3);
 }

 @After
  public void m2()
 {
  System.out.println("after");
 }

 @BeforeClass
  public static void m3()
  {
   System.out.println("start");
  };

 @AfterClass
  public static void m4()
  {
   System.out.println("stop");
  };

};

///java org.junit.runner.JUnitCore com.test.H1Test
//javac -d .

編譯後執行下面的運行命令……
java org.junit.runner.JUnitCore com.test.H1Test


====================================================================

package com.test;

import org.junit.*;
import static org.junit.Assert.*;
import com.web.*;

public class H1Test
{
 H1 h1 = new H1();

 @Before
  public void m1()
 {
  System.out.println("before");
  
 }

 @Test
  public void t1()
 {
  System.out.println("1");
  assertEquals((1+1),2);
 }

 @Test
  public void t2()
 {
  System.out.println("2");
  assertEquals((1+2),3);
 }

 @Test
  public void t3()
 {
  System.out.println("3");
  assertEquals(h1.add(3,4),7);
 }

 @After
  public void m2()
 {
  System.out.println("after");
 }

 @BeforeClass
  public static void m3()
  {
   System.out.println("start");
  };

 @AfterClass
  public static void m4()
  {
   System.out.println("stop");
  };

};

///java org.junit.runner.JUnitCore com.test.H1Test
//javac -d .

td:testdirector Mercury
ibm:rose:cq:clearquest  (測試管理工具:生成測試計劃和測試用例)
winrunner:自動化測試(主要用於黑盒測試,也就是功能測試,需要參考需求文檔)
loadrunner:負載測試(壓力測試):可以產生虛擬用戶,比如產生虛擬用戶1萬人去檢測軟件

===========================================================================
oracle:
啓動:服務器端進程、服務進程
1、啓動服務器端進程 oracle sid(不是數據庫名)
2、通過客戶端進程連接服務器端進程 sqlplus /nolog (不登錄:nologin)
3、連接到實例上 set oracle_sid=java (sid)

connect / as sysdba
/:區分用戶名和密碼:username/password,如果不寫代表用戶名和密碼是任意的

4、啓動數據庫:startup
startup nomount :只加載實例
startup mount:加載控制文件

5、身份驗證:有兩種方式
1、通過操作系統身份驗證
2、通過數據庫驗證

connect / as sysdba:通過操作系統驗證:在數據庫沒有打開的時候只能使用這種方式

對登錄到操作系統的用戶要求必須是屬於ora_dba組!
以操作系統身份驗證登錄映射數據庫用戶是sys用戶

Connection conn = DataSource.getConnection() ;
CallableStatement cstmt = cn.prepareCall("{call insert_user ?,?,?}") ;

cstmt.registerOutParameter(1,Types.INTEGER);//設置輸出參數
cstmt.setParameter(2,'zxx');//設置輸入參數
cstmt.setParameter(3,'123');
cstmt.execute();
cstmt.getInt(1);//取出了下面存儲過程返回的值(也就是剛纔插入的用戶的id),同時也插入了剛纔的用戶zxx

//@password和@name是輸入參數,@id是輸出參數,因爲後面有個out!
create procedure insert_user(@id int out,@name varchar(20),@password varchar(20))
begin transaction
 insert into user(name,password) values(@name,@password);
 select @id=max(id) from user ;
commit

-------------------------------------
Oracle分頁(第六天裏面講的)
select * from
(
 select last_name,rownum as id from employees
 where rownum<21
)
where id > 11 ;

既然不能夠讓rownum大於一個具體的非0值,那麼先構造一個第一到20個
記錄的表,這個表中把rownum的字段抽象成一個別名叫做id
這個id可以作爲條件來選擇……

這就是分頁的解決方法了……在mysql中不支持rownum,所以只有oracle才能
用這種方法分頁,mysql中有別的方法來分頁!
------------------------------------------------------------------
一個Oracle的存儲過程的示例:
package abc;

import java.sql.*;

public class H1
{
 public static void main(String[] args) throws Exception
 {
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection conn = DriverManager
   .getConnection("jdbc:oracle:thin:@202.112.85.25:1521:webtest","scott","tiger");
  String procedure = "{ call savedata(?) }";
  CallableStatement cs = conn.prepareCall(procedure);
  cs.setInt(1,100);
  cs.executeUpdate();
  cs.close();
  conn.close();

 }
};

 

create table ht3
(
id int not null primary key,
name varchar(5) not null
);

 

create or replace procedure savedata
(i in number)
as
begin
insert into ht3 values (i,'s' || i);
end;
/


SQLServer的隨機:

select top 5 * from sales order by newid()
//實現隨機選5行的方法。
----------------------------------
SQLServer的分頁:

select top 3 * from Grade where Player='選手一' and ID not in
        (select top 3 ID from Grade where player='選手一')
===========================================================

1. Given:

1. public class test (
2.   public static void main (String args[])    {
3.       int  i = 0xFFFFFFF1;
4.       int  j = ~i;
5. 
6.      }
7. )

What is the decimal value of j at line 5?

A. 0
B. 1
C. 14
D. -15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.

2. Given:

Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);

Which two expressions evaluate to True? (Choose Two)

A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))

3. Click the exhibit button:

1. public class test (   
2.          private static int j = 0;
3.       
4.        private static boolean methodB(int k) (
5.                j += k;
6.                return true;
7. )
8.
9. public static void methodA(int  i) {
10.          boolean b:  
11.          b = i < 10 | methodB (4);
12.          b = i < 10 || methodB (8);
13. )
14.
15.  public static void main (String args[] }   (
16.              methodA (0);
17.              system.out.printIn(j);
18.            )
19. )

What is the result?

A. The program prints “0”
B. The program prints “4”
C. The program prints “8”
D. The program prints “12”
E. The code does not complete

4. Given:

1.Public class test (
2.    Public static void main (String args[])  (
3.     System.out.printIn (6 ^ 3);
4.   )
5.)

What is the output?

Ans:


5. Given:

1. public class Foo {
2.   public static void main (String [] args)  {
3.      StringBuffer a = new StringBuffer (“A”);
4.      StringBuffer b = new StringBuffer (“B”);
5.     operate (a,b);
6.     system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y)  {
9.           x.append {y};
10.           y = x;
11.     )
12. }

What is the result?

A. The code compiles and prints “A,B”.
B. The code compiles and prints “A,A”.
C. The code compiles and prints “B,B”.
D. The code compiles and prints “AB,B”.
E. The code compiles and prints “AB,AB”.
F. The code does not compile because “+” cannot be overloaded for StringBuffer.

6. Click the exhibit button:

1. Public class test (
2. Public static void stringReplace (String text)  (
3.      Text = text.replace (‘j’ , ‘i’);
4. )
5. 
6. public static void bufferReplace (StringBuffer text)  (
7.     text = text.append (“C”)
8. )
9. 
10. public static void main (String args[]}  (
11.    String textString = new String (“java”);
12.    StringBuffer text BufferString = new StringBuffer (“java”);
13. 
14.     stringReplace (textString);
15.     BufferReplace (textBuffer);
16. 
17.     System.out.printIn (textString + textBuffer);
18.     }
19.  )

What is the output?
Ans:


7. Click the Exhibit button:

1. public class test {
2.      public static void add3 (Integer i) }
3.      int val = i.intValue ( );
4.           val += 3;
5.           i = new Integer (val);
6.      }
7. 
8.   public static void main (String args [ ] )  {
9.    Integer  i = new Integer (0);
10.     add3 (i);
11.      system.out.printIn (i.intValue ( )  );
12.   }
13. )

What is the result?

A. Compilation will fail.
B. The program prints “0”.
C. The program prints “3”.
D. Compilation will succeed but an exception will be thrown at line 3.

8. Given:

1. public class ConstOver {
2.   public ConstOver (int x, int y, int z)  {
3.      }
4. }

Which two overload the ConstOver constructor? (Choose Two)

A. ConstOver ( ) { }
B. Protected int ConstOver ( ) { }
C. Private ConstOver (int z, int y, byte x) { }
D. public Object ConstOver (int x, int y, int z) { }
E. public void ConstOver (byte x, byte y, byte z) { }

9. Given:

1. public class MethodOver  {
2.     public void setVar (int a, int b, float c)  {
3.     }
4. }

Which two overload the setVar method? (Choose Two)

A. private void setVar (int a, float c, int b)  { }
B. protected void setVar (int a, int b, float c) { }
C. public int setVar (int a, float c, int b) (return a;)
D. public int setVar (int a, int b, float c) (return a;)
E. protected float setVar (int a, int b, float c) (return c;)

10. Given:

1. class BaseClass {
2.    Private float x = 1.0f ;
3.     protected float getVar ( ) ( return x;)
4. }
5. class Subclass extends BaseClass (
6.       private float x = 2.0f;
7.       //insert code here
8. )

Which two are valid examples of method overriding? (Choose Two)

A. float getVar ( ) { return x;}
B. public float getVar ( ) { return x;}
C. float double getVar ( ) { return x;}
D. protected float getVar ( ) { return x;}
E. public float getVar (float f ) { return f;}

11. Which two demonstrate an “is a” relationship? (Choose Two)

A. public interface Person { }
public class Employee extends Person { }
B. public interface Shape { }
public class Employee extends Shape { }
C. public interface Color { }
public class Employee extends Color { }
D. public class Species { }
public class Animal (private Species species;)
E. interface Component { }
Class Container implements Component (
         Private Component[ ] children;
)

12. Which statement is true?

A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement multiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the
enclosing outer class.

13. Given:

1. package foo;
2. 
3. public class Outer (
4.    public static class Inner (
5.    )
6. )

Which statement is true?

A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer
class
D. From within the package bar, an instance of the inner class can be constructed
with “new inner()”

14. Click the exhibit button:

1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class
inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new
enclosingone (); 7. //insert code here 8. ) 9. )

Which statement at line 7 constructs an instance of the inner class?

A. InsideOnew ei= eo.new InsideOn();
B. Eo.InsideOne ei = eo.new InsideOne();
C. InsideOne ei = EnclosingOne.new InsideOne();
D. EnclosingOne.InsideOne ei = eo.new InsideOne();

15. Click the exhibit button:

1. interface foo { 2. int k = 0; 3. ] 4.   5. public class test implements Foo ( 6.
public static void main(String args[]) ( 7. int i; 8. Test test = new test (); 9.
i= test.k; 10. i= Test.k; 11. i= Foo.k; 12. ) 13. ) 14.     

What is the result?

A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.

16.  Given:

1. //point X
2. public class foo (
3. public static void main (String[]args) throws Exception {
4. printWriter out = new PrintWriter (new
5. java.io.outputStreamWriter (System.out), true;
6. out.printIn(“Hello”);
7. }
8. )

Which statement at PointX on line 1 allows this code to compile and run?

A. import java.io.PrintWriter;
B. include java.io.PrintWriter;
C. import java.io.OutputStreamWriter;
D. include java.io.OutputStreamWriter;
E. no statement is needed.

======================================================
Connectin cn = DataSource.getConnection();
CallableStatement cstmt = cn.prepareCall("{call myproc ?}");
cstmt.registerOutParameter(1,Types.INTEGER);
cstmt.execute();
cstmt.getInt(1);

create procedure inser_user(@id int out,@name varchar(20),@password varchar(20))
begin transaction
 insert into user(name,password) values(@name,@password);
 select @id=max(id) from user;
commit

Connectin cn = DataSource.getConnection();
CallableStatement cstmt = cn.prepareCall("{call inser_user ?,?,?}");
cstmt.registerOutParameter(1,Types.INTEGER);
cstmt.setParameter(2,'zxx');
cstmt.setParameter(3,'123');
cstmt.execute();
cstmt.getInt(1);

oracle分頁
//select rownum from User where rownum<40 and rownum>30
select * from (select * ,rownum as r from user where rownum<41) where r>30
select * from((select * from ((select from User) as u)
 where u.rownum<40) as u2) where u2.rownum>30

sql server分頁

(select top 10 * not in (select top 30 from user) from user;

mysql
 select * from user limit 10,10

select top 5 * from sales order by newid()

package abc;

import java.sql.*;

public class H1
{
 public static void main(String[] args) throws Exception
 {
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection conn = DriverManager
   .getConnection("jdbc:oracle:thin:@202.112.85.25:1521:webtest","scott","tiger");
  String procedure = "{ call savedata(?) }";
  CallableStatement cs = conn.prepareCall(procedure);
  cs.setInt(1,100);
  cs.executeUpdate();
  cs.close();
  conn.close();

 }
};

 

create table ht3
(
id int not null primary key,
name varchar(5) not null
);

 

create or replace procedure savedata
(i in number)
as
begin
insert into ht3 values (i,'s' || i);
end;
/


====================================================================
====================================================================
上面的東西很亂吧……確實是,今天由於下午1:20有個面試,所以上午的課沒怎麼好好聽,結果面試的時候沒有問
一點和技術有關的問題,結果反倒是我被將了一軍。這個面試的是個中年女性,看樣子不像是個搞技術的,但是她
也沒有對付我,反倒認真的幫我分析了一下我現在心態的問題,確實,這是個值得好好考慮的問題……

事情其實很清楚,只不過我一直不願意看清楚:甭管什麼樣子的培訓,出來後想3000就業幾乎都是不可能的,
除非你包裝簡歷並且謊稱自己有1到2年的工作經驗,在某某公司做過什麼什麼項目云云,如果把面試你的人給
騙過去了,再加上你忽悠的本領不錯的話,那麼月薪3000或是4000多都是可以做到的……聽上去挺彆扭,但是事實
確實如此,如果你不騙,實話實說,那麼你的月薪水平就是2000到2500,沒有任何爭議,這也是現今社會公認
的程序員的價格尺度……現在的問題就是:我該不該騙……??

下週好像會開始簡歷的包裝工作,通過添加進去一些“項目經驗”和“工作經歷”來達到最大化未來月薪的目的……
“你認爲你真的適合做軟件開發工作麼,軟件開發工作可是很枯燥的……”對於一個前來應聘軟件開發工作的沒有
工作經驗的人說這些話也可以算的上是一種體貼吧,如果是個做技術的面試我他是肯定不會說這些東西的。

“你認爲你最喜歡的工作是什麼呢?”
這話問的有意思,如果我知道我自己喜歡做什麼樣的工作,我肯定不會爲了這個工作而培訓的,有了興趣基本上
就有了一切,一般來說是這樣的……當時我沒能回答出來,事後想想,如果這世界上真的有什麼職業是我喜歡做的,
那我目前唯一能夠想到的就是播音員了,我喜歡照着英文稿子念,而且念個一個小時什麼的都不帶煩的,
這毛病不知道是什麼時候養成的……

“爲什麼不自學,而選擇培訓機構呢?”
這話把我噁心壞了,當時語塞,什麼都說不出來了……完全是自己的問題,有什麼好說的呢,答案明擺着,沒有自我
充實,自我學習的動機和心態,缺乏危機意識,競爭意識什麼的,獨生子女的那些臭毛病儘管往我身上扔好了,扔
多少都能接得住……如果今天我被問到這樣的問題還能夠理直氣壯的給自己找到一個藉口的話,那簡直是無恥到極點
了(還好我沒無恥到那種程度)

“擺正自己的心態,踏實做事,再想到自己待遇的時候先想一想自己能爲公司做什麼”
這句話可有意思了,今天面試回來大概的和張老師說了一下情況,他也叫我擺正心態,要自信一些,就說自己有
一年工作經驗……兩邊都是擺正心態,但是含義卻完全不一樣,該選擇哪一邊呢……?

從那裏回來後,3點半方正技術研究院又從班裏挑了5個人去筆試,本來是沒我什麼事的,要不是張老師又把我加上的
話我還真去不了,這真得好好謝謝他,筆試的題目不是很難,東拉西扯的1個小時筆都沒停,答完正好也收捲了,不知
最終情況怎麼樣,這一次我學乖了,在期望月薪那裏寫了個2400,這應該是沒有工作經驗又能夠勝任一些基本工作的
人的相對來說比較不過分的要價了吧,這麼寫應該是不得罪人的,就是不知道最後到底會怎麼樣。一期的李結也是,
在方正這裏做完題目後感到容易至極,結果人家最後沒有要他,有的時候買方和賣方是很難一致的,同一個事物在不同
人、不同立場看來差別也是很大的。

上面那些雜七雜八的東西是今天兩位張老師講的東西,有一個是講linux的張老師,據說他在大學的時候曾經是長跑
5000米和10000米的好手,真難以置信啊,看他的樣子並不是太外向,雖然和人交流什麼的看不出來,但是總覺得
他很內斂,而搞運動的好手一般情況下總讓人想到外向……

這個張老師講課很專業,Oracle、Linux、Java、各種專業工具什麼的都玩的相當的熟練,好像是由於自己目前的
企業效益不好所以出來做培訓講師(聽說的)……

只是由於太專業,有的時候讓人覺得真是有些……跟不上,再加上現在面試筆試什麼的,也沒什麼太多的心情仔細聽那些
專用測試工具的具體使用方法了,昨天和今天上午涉及到的那個在線聊天的swing的CS的東西,涉及Socket編程,是
我的絕對弱項中的弱項,得好好看馬士兵的教程補一補,所以幾乎沒有聽懂……

=========================================================================================

扯得太遠了,其實現在的核心問題是我到底在不在簡歷上面撒謊……我真的不願意,因爲這並非自己本性,也非自己所願,
可是如果真的實話實說,那麼最後面臨的將會是看到周遭人士一個個的3500或是4000的離開,到那時自己還能否保持
心理平衡也是個問題……

所以事情就是這樣,你要麼就乾脆做個從裏到外都不在乎撒謊的人,要麼就乾脆做個本本分分,由裏到外都實實在在的、
不在乎別人怎麼做的人,就怕你處在中間狀態,退也不是,進也不是,高不成、低不就,這就鬱悶了……

心理學上這叫做自我之間的衝突,任何心理方面的煩惱、憂慮幾乎全是由於人格方面的衝突導致的,你要是有本事把
除了主人格外的其他人格全部殺乾淨會感到日子輕鬆不少,其實很多時候並不是外面的東西給了你多大多大的壓力,
壓力都是由你腦殼中的那灘漿糊造出來的,掌控了那灘漿糊,你就掌控了一切,爲什麼有的人會信奉宗教或神靈呢?
還是腦殼裏面的那灘漿糊搞的,什麼時候人類能控制了它、人類也就控制了一切,像什麼記憶移植之類的也就不是
夢想了。聽起來荒謬,但是值得期待……

思來想去我還是不太想撒謊,確實不太想,那就接受低薪待遇吧,這年頭誠實也是有代價的,想在這個充斥了謊言
的社會,這誠實的心態、撒謊就臉紅的心態我不知能夠保持多久,往好了說這是正直,往不好了說這叫傻、蠢、不懂得
混社會,當很多人憑藉着謊言獲得很好的待遇的時候,誠信在這個社會也逐漸變得一錢不值,這也就不難理解爲什麼在
電影“夜宴”中葛優的一句臺詞“我泱泱大國,誠信爲本”能夠引發鬨堂大笑了……

昨天的程序中還可以考慮添加菜單項,

關鍵代碼(打開文件):

String filePath = "";
    File file = null;
    BufferedReader br;
    String content = "";
   
    public void jMenuItem2_actionPerformed(ActionEvent e) {
        if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
           file = fileChooser.getSelectedFile();
           filePath = file.getAbsolutePath();
           //JOptionPane.showMessageDialog(this,"file:" + filePath);
           try {
             br = new BufferedReader(new FileReader(file));
             content = br.readLine();
             while (content != null){
                 text.append(content + "/n");
                 content = br.readLine();
             }
           }catch(Exception ee){
               ee.printStackTrace();
           }
        
          
        }
    }

 

-----------------------------------------------------------
每個測試方法先調用@Before,然後調用測試方法@Test,再調用@After,
也就是說@Before和@After是每個測試方法都必須調用的!
其實就是那個SetUp和TearDown方法,只不過由於版本的不同導致稱呼不同而已……

有一個@BeforeClass只調用一次

一個簡單的測試示例如下:

package com.test;

import org.junit.*;
import static org.junit.Assert.*;

public class H1Test
{
 @Before
  public void m1()
 {
  System.out.println("before");
 }

 @Test
  public void t1()
 {
  System.out.println("1");
  assertEquals((1+1),2);
 }

 @Test
  public void t2()
 {
  System.out.println("2");
  assertEquals((1+2),3);
 }

 @After
  public void m2()
 {
  System.out.println("after");
 }

 @BeforeClass
  public static void m3()
  {
   System.out.println("start");
  };

 @AfterClass
  public static void m4()
  {
   System.out.println("stop");
  };

};

///java org.junit.runner.JUnitCore com.test.H1Test
//javac -d .

編譯後執行下面的運行命令……
java org.junit.runner.JUnitCore com.test.H1Test


====================================================================

package com.test;

import org.junit.*;
import static org.junit.Assert.*;
import com.web.*;

public class H1Test
{
 H1 h1 = new H1();

 @Before
  public void m1()
 {
  System.out.println("before");
  
 }

 @Test
  public void t1()
 {
  System.out.println("1");
  assertEquals((1+1),2);
 }

 @Test
  public void t2()
 {
  System.out.println("2");
  assertEquals((1+2),3);
 }

 @Test
  public void t3()
 {
  System.out.println("3");
  assertEquals(h1.add(3,4),7);
 }

 @After
  public void m2()
 {
  System.out.println("after");
 }

 @BeforeClass
  public static void m3()
  {
   System.out.println("start");
  };

 @AfterClass
  public static void m4()
  {
   System.out.println("stop");
  };

};

///java org.junit.runner.JUnitCore com.test.H1Test
//javac -d .

td:testdirector Mercury
ibm:rose:cq:clearquest  (測試管理工具:生成測試計劃和測試用例)
winrunner:自動化測試(主要用於黑盒測試,也就是功能測試,需要參考需求文檔)
loadrunner:負載測試(壓力測試):可以產生虛擬用戶,比如產生虛擬用戶1萬人去檢測軟件

===========================================================================
oracle:
啓動:服務器端進程、服務進程
1、啓動服務器端進程 oracle sid(不是數據庫名)
2、通過客戶端進程連接服務器端進程 sqlplus /nolog (不登錄:nologin)
3、連接到實例上 set oracle_sid=java (sid)

connect / as sysdba
/:區分用戶名和密碼:username/password,如果不寫代表用戶名和密碼是任意的

4、啓動數據庫:startup
startup nomount :只加載實例
startup mount:加載控制文件

5、身份驗證:有兩種方式
1、通過操作系統身份驗證
2、通過數據庫驗證

connect / as sysdba:通過操作系統驗證:在數據庫沒有打開的時候只能使用這種方式

對登錄到操作系統的用戶要求必須是屬於ora_dba組!
以操作系統身份驗證登錄映射數據庫用戶是sys用戶

Connection conn = DataSource.getConnection() ;
CallableStatement cstmt = cn.prepareCall("{call insert_user ?,?,?}") ;

cstmt.registerOutParameter(1,Types.INTEGER);//設置輸出參數
cstmt.setParameter(2,'zxx');//設置輸入參數
cstmt.setParameter(3,'123');
cstmt.execute();
cstmt.getInt(1);//取出了下面存儲過程返回的值(也就是剛纔插入的用戶的id),同時也插入了剛纔的用戶zxx

//@password和@name是輸入參數,@id是輸出參數,因爲後面有個out!
create procedure insert_user(@id int out,@name varchar(20),@password varchar(20))
begin transaction
 insert into user(name,password) values(@name,@password);
 select @id=max(id) from user ;
commit

-------------------------------------
Oracle分頁(第六天裏面講的)
select * from
(
 select last_name,rownum as id from employees
 where rownum<21
)
where id > 11 ;

既然不能夠讓rownum大於一個具體的非0值,那麼先構造一個第一到20個
記錄的表,這個表中把rownum的字段抽象成一個別名叫做id
這個id可以作爲條件來選擇……

這就是分頁的解決方法了……在mysql中不支持rownum,所以只有oracle才能
用這種方法分頁,mysql中有別的方法來分頁!
------------------------------------------------------------------
一個Oracle的存儲過程的示例:
package abc;

import java.sql.*;

public class H1
{
 public static void main(String[] args) throws Exception
 {
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection conn = DriverManager
   .getConnection("jdbc:oracle:thin:@202.112.85.25:1521:webtest","scott","tiger");
  String procedure = "{ call savedata(?) }";
  CallableStatement cs = conn.prepareCall(procedure);
  cs.setInt(1,100);
  cs.executeUpdate();
  cs.close();
  conn.close();

 }
};

 

create table ht3
(
id int not null primary key,
name varchar(5) not null
);

 

create or replace procedure savedata
(i in number)
as
begin
insert into ht3 values (i,'s' || i);
end;
/


SQLServer的隨機:

select top 5 * from sales order by newid()
//實現隨機選5行的方法。
----------------------------------
SQLServer的分頁:

select top 3 * from Grade where Player='選手一' and ID not in
        (select top 3 ID from Grade where player='選手一')
===========================================================

1. Given:

1. public class test (
2.   public static void main (String args[])    {
3.       int  i = 0xFFFFFFF1;
4.       int  j = ~i;
5. 
6.      }
7. )

What is the decimal value of j at line 5?

A. 0
B. 1
C. 14
D. -15
E. An error at line 3 causes compilation to fail.
F. An error at line 4 causes compilation to fail.

2. Given:

Integer i = new Integer (42);
Long 1 = new Long (42);
Double d = new Double (42.0);

Which two expressions evaluate to True? (Choose Two)

A. (i ==1)
B. (i == d)
C. (d == 1)
D. (i.equals (d))
E. (d.equals (i))
F. (i.equals (42))

3. Click the exhibit button:

1. public class test (   
2.          private static int j = 0;
3.       
4.        private static boolean methodB(int k) (
5.                j += k;
6.                return true;
7. )
8.
9. public static void methodA(int  i) {
10.          boolean b:  
11.          b = i < 10 | methodB (4);
12.          b = i < 10 || methodB (8);
13. )
14.
15.  public static void main (String args[] }   (
16.              methodA (0);
17.              system.out.printIn(j);
18.            )
19. )

What is the result?

A. The program prints “0”
B. The program prints “4”
C. The program prints “8”
D. The program prints “12”
E. The code does not complete

4. Given:

1.Public class test (
2.    Public static void main (String args[])  (
3.     System.out.printIn (6 ^ 3);
4.   )
5.)

What is the output?

Ans:


5. Given:

1. public class Foo {
2.   public static void main (String [] args)  {
3.      StringBuffer a = new StringBuffer (“A”);
4.      StringBuffer b = new StringBuffer (“B”);
5.     operate (a,b);
6.     system.out.printIn{a + “,” +b};
7. )
8. static void operate (StringBuffer x, StringBuffer y)  {
9.           x.append {y};
10.           y = x;
11.     )
12. }

What is the result?

A. The code compiles and prints “A,B”.
B. The code compiles and prints “A,A”.
C. The code compiles and prints “B,B”.
D. The code compiles and prints “AB,B”.
E. The code compiles and prints “AB,AB”.
F. The code does not compile because “+” cannot be overloaded for StringBuffer.

6. Click the exhibit button:

1. Public class test (
2. Public static void stringReplace (String text)  (
3.      Text = text.replace (‘j’ , ‘i’);
4. )
5. 
6. public static void bufferReplace (StringBuffer text)  (
7.     text = text.append (“C”)
8. )
9. 
10. public static void main (String args[]}  (
11.    String textString = new String (“java”);
12.    StringBuffer text BufferString = new StringBuffer (“java”);
13. 
14.     stringReplace (textString);
15.     BufferReplace (textBuffer);
16. 
17.     System.out.printIn (textString + textBuffer);
18.     }
19.  )

What is the output?
Ans:


7. Click the Exhibit button:

1. public class test {
2.      public static void add3 (Integer i) }
3.      int val = i.intValue ( );
4.           val += 3;
5.           i = new Integer (val);
6.      }
7. 
8.   public static void main (String args [ ] )  {
9.    Integer  i = new Integer (0);
10.     add3 (i);
11.      system.out.printIn (i.intValue ( )  );
12.   }
13. )

What is the result?

A. Compilation will fail.
B. The program prints “0”.
C. The program prints “3”.
D. Compilation will succeed but an exception will be thrown at line 3.

8. Given:

1. public class ConstOver {
2.   public ConstOver (int x, int y, int z)  {
3.      }
4. }

Which two overload the ConstOver constructor? (Choose Two)

A. ConstOver ( ) { }
B. Protected int ConstOver ( ) { }
C. Private ConstOver (int z, int y, byte x) { }
D. public Object ConstOver (int x, int y, int z) { }
E. public void ConstOver (byte x, byte y, byte z) { }

9. Given:

1. public class MethodOver  {
2.     public void setVar (int a, int b, float c)  {
3.     }
4. }

Which two overload the setVar method? (Choose Two)

A. private void setVar (int a, float c, int b)  { }
B. protected void setVar (int a, int b, float c) { }
C. public int setVar (int a, float c, int b) (return a;)
D. public int setVar (int a, int b, float c) (return a;)
E. protected float setVar (int a, int b, float c) (return c;)

10. Given:

1. class BaseClass {
2.    Private float x = 1.0f ;
3.     protected float getVar ( ) ( return x;)
4. }
5. class Subclass extends BaseClass (
6.       private float x = 2.0f;
7.       //insert code here
8. )

Which two are valid examples of method overriding? (Choose Two)

A. float getVar ( ) { return x;}
B. public float getVar ( ) { return x;}
C. float double getVar ( ) { return x;}
D. protected float getVar ( ) { return x;}
E. public float getVar (float f ) { return f;}

11. Which two demonstrate an “is a” relationship? (Choose Two)

A. public interface Person { }
public class Employee extends Person { }
B. public interface Shape { }
public class Employee extends Shape { }
C. public interface Color { }
public class Employee extends Color { }
D. public class Species { }
public class Animal (private Species species;)
E. interface Component { }
Class Container implements Component (
         Private Component[ ] children;
)

12. Which statement is true?

A. An anonymous inner class may be declared as final
B. An anonymous inner class can be declared as private
C. An anonymous inner class can implement multiple interfaces
D. An anonymous inner class can access final variables in any enclosing scope
E. Construction of an instance of a static inner class requires an instance of the
enclosing outer class.

13. Given:

1. package foo;
2. 
3. public class Outer (
4.    public static class Inner (
5.    )
6. )

Which statement is true?

A. An instance of the Inner class can be constructed with “new Outer.Inner ()”
B. An instance of the inner class cannot be constructed outside of package foo
C. An instance of the inner class can only be constructed from within the outer
class
D. From within the package bar, an instance of the inner class can be constructed
with “new inner()”

14. Click the exhibit button:

1. public class enclosingone ( 2. public class insideone{} 3. ) 4. public class
inertest( 5. public static void main (string[]args)( 6. enclosingone eo= new
enclosingone (); 7. //insert code here 8. ) 9. )

Which statement at line 7 constructs an instance of the inner class?

A. InsideOnew ei= eo.new InsideOn();
B. Eo.InsideOne ei = eo.new InsideOne();
C. InsideOne ei = EnclosingOne.new InsideOne();
D. EnclosingOne.InsideOne ei = eo.new InsideOne();

15. Click the exhibit button:

1. interface foo { 2. int k = 0; 3. ] 4.   5. public class test implements Foo ( 6.
public static void main(String args[]) ( 7. int i; 8. Test test = new test (); 9.
i= test.k; 10. i= Test.k; 11. i= Foo.k; 12. ) 13. ) 14.     

What is the result?

A. Compilation succeeds.
B. An error at line 2 causes compilation to fail.
C. An error at line 9 causes compilation to fail.
D. An error at line 10 causes compilation to fail.
E. An error at line 11 causes compilation to fail.

16.  Given:

1. //point X
2. public class foo (
3. public static void main (String[]args) throws Exception {
4. printWriter out = new PrintWriter (new
5. java.io.outputStreamWriter (System.out), true;
6. out.printIn(“Hello”);
7. }
8. )

Which statement at PointX on line 1 allows this code to compile and run?

A. import java.io.PrintWriter;
B. include java.io.PrintWriter;
C. import java.io.OutputStreamWriter;
D. include java.io.OutputStreamWriter;
E. no statement is needed.

======================================================
Connectin cn = DataSource.getConnection();
CallableStatement cstmt = cn.prepareCall("{call myproc ?}");
cstmt.registerOutParameter(1,Types.INTEGER);
cstmt.execute();
cstmt.getInt(1);

create procedure inser_user(@id int out,@name varchar(20),@password varchar(20))
begin transaction
 insert into user(name,password) values(@name,@password);
 select @id=max(id) from user;
commit

Connectin cn = DataSource.getConnection();
CallableStatement cstmt = cn.prepareCall("{call inser_user ?,?,?}");
cstmt.registerOutParameter(1,Types.INTEGER);
cstmt.setParameter(2,'zxx');
cstmt.setParameter(3,'123');
cstmt.execute();
cstmt.getInt(1);

oracle分頁
//select rownum from User where rownum<40 and rownum>30
select * from (select * ,rownum as r from user where rownum<41) where r>30
select * from((select * from ((select from User) as u)
 where u.rownum<40) as u2) where u2.rownum>30

sql server分頁

(select top 10 * not in (select top 30 from user) from user;

mysql
 select * from user limit 10,10

select top 5 * from sales order by newid()

package abc;

import java.sql.*;

public class H1
{
 public static void main(String[] args) throws Exception
 {
  Class.forName("oracle.jdbc.driver.OracleDriver");
  Connection conn = DriverManager
   .getConnection("jdbc:oracle:thin:@202.112.85.25:1521:webtest","scott","tiger");
  String procedure = "{ call savedata(?) }";
  CallableStatement cs = conn.prepareCall(procedure);
  cs.setInt(1,100);
  cs.executeUpdate();
  cs.close();
  conn.close();

 }
};

 

create table ht3
(
id int not null primary key,
name varchar(5) not null
);

 

create or replace procedure savedata
(i in number)
as
begin
insert into ht3 values (i,'s' || i);
end;
/


====================================================================
====================================================================
上面的東西很亂吧……確實是,今天由於下午1:20有個面試,所以上午的課沒怎麼好好聽,結果面試的時候沒有問
一點和技術有關的問題,結果反倒是我被將了一軍。這個面試的是個中年女性,看樣子不像是個搞技術的,但是她
也沒有對付我,反倒認真的幫我分析了一下我現在心態的問題,確實,這是個值得好好考慮的問題……

事情其實很清楚,只不過我一直不願意看清楚:甭管什麼樣子的培訓,出來後想3000就業幾乎都是不可能的,
除非你包裝簡歷並且謊稱自己有1到2年的工作經驗,在某某公司做過什麼什麼項目云云,如果把面試你的人給
騙過去了,再加上你忽悠的本領不錯的話,那麼月薪3000或是4000多都是可以做到的……聽上去挺彆扭,但是事實
確實如此,如果你不騙,實話實說,那麼你的月薪水平就是2000到2500,沒有任何爭議,這也是現今社會公認
的程序員的價格尺度……現在的問題就是:我該不該騙……??

下週好像會開始簡歷的包裝工作,通過添加進去一些“項目經驗”和“工作經歷”來達到最大化未來月薪的目的……
“你認爲你真的適合做軟件開發工作麼,軟件開發工作可是很枯燥的……”對於一個前來應聘軟件開發工作的沒有
工作經驗的人說這些話也可以算的上是一種體貼吧,如果是個做技術的面試我他是肯定不會說這些東西的。

“你認爲你最喜歡的工作是什麼呢?”
這話問的有意思,如果我知道我自己喜歡做什麼樣的工作,我肯定不會爲了這個工作而培訓的,有了興趣基本上
就有了一切,一般來說是這樣的……當時我沒能回答出來,事後想想,如果這世界上真的有什麼職業是我喜歡做的,
那我目前唯一能夠想到的就是播音員了,我喜歡照着英文稿子念,而且念個一個小時什麼的都不帶煩的,
這毛病不知道是什麼時候養成的……

“爲什麼不自學,而選擇培訓機構呢?”
這話把我噁心壞了,當時語塞,什麼都說不出來了……完全是自己的問題,有什麼好說的呢,答案明擺着,沒有自我
充實,自我學習的動機和心態,缺乏危機意識,競爭意識什麼的,獨生子女的那些臭毛病儘管往我身上扔好了,扔
多少都能接得住……如果今天我被問到這樣的問題還能夠理直氣壯的給自己找到一個藉口的話,那簡直是無恥到極點
了(還好我沒無恥到那種程度)

“擺正自己的心態,踏實做事,再想到自己待遇的時候先想一想自己能爲公司做什麼”
這句話可有意思了,今天面試回來大概的和張老師說了一下情況,他也叫我擺正心態,要自信一些,就說自己有
一年工作經驗……兩邊都是擺正心態,但是含義卻完全不一樣,該選擇哪一邊呢……?

從那裏回來後,3點半方正技術研究院又從班裏挑了5個人去筆試,本來是沒我什麼事的,要不是張老師又把我加上的
話我還真去不了,這真得好好謝謝他,筆試的題目不是很難,東拉西扯的1個小時筆都沒停,答完正好也收捲了,不知
最終情況怎麼樣,這一次我學乖了,在期望月薪那裏寫了個2400,這應該是沒有工作經驗又能夠勝任一些基本工作的
人的相對來說比較不過分的要價了吧,這麼寫應該是不得罪人的,就是不知道最後到底會怎麼樣。一期的李結也是,
在方正這裏做完題目後感到容易至極,結果人家最後沒有要他,有的時候買方和賣方是很難一致的,同一個事物在不同
人、不同立場看來差別也是很大的。

上面那些雜七雜八的東西是今天兩位張老師講的東西,有一個是講linux的張老師,據說他在大學的時候曾經是長跑
5000米和10000米的好手,真難以置信啊,看他的樣子並不是太外向,雖然和人交流什麼的看不出來,但是總覺得
他很內斂,而搞運動的好手一般情況下總讓人想到外向……

這個張老師講課很專業,Oracle、Linux、Java、各種專業工具什麼的都玩的相當的熟練,好像是由於自己目前的
企業效益不好所以出來做培訓講師(聽說的)……

只是由於太專業,有的時候讓人覺得真是有些……跟不上,再加上現在面試筆試什麼的,也沒什麼太多的心情仔細聽那些
專用測試工具的具體使用方法了,昨天和今天上午涉及到的那個在線聊天的swing的CS的東西,涉及Socket編程,是
我的絕對弱項中的弱項,得好好看馬士兵的教程補一補,所以幾乎沒有聽懂……

=========================================================================================

扯得太遠了,其實現在的核心問題是我到底在不在簡歷上面撒謊……我真的不願意,因爲這並非自己本性,也非自己所願,
可是如果真的實話實說,那麼最後面臨的將會是看到周遭人士一個個的3500或是4000的離開,到那時自己還能否保持
心理平衡也是個問題……

所以事情就是這樣,你要麼就乾脆做個從裏到外都不在乎撒謊的人,要麼就乾脆做個本本分分,由裏到外都實實在在的、
不在乎別人怎麼做的人,就怕你處在中間狀態,退也不是,進也不是,高不成、低不就,這就鬱悶了……

心理學上這叫做自我之間的衝突,任何心理方面的煩惱、憂慮幾乎全是由於人格方面的衝突導致的,你要是有本事把
除了主人格外的其他人格全部殺乾淨會感到日子輕鬆不少,其實很多時候並不是外面的東西給了你多大多大的壓力,
壓力都是由你腦殼中的那灘漿糊造出來的,掌控了那灘漿糊,你就掌控了一切,爲什麼有的人會信奉宗教或神靈呢?
還是腦殼裏面的那灘漿糊搞的,什麼時候人類能控制了它、人類也就控制了一切,像什麼記憶移植之類的也就不是
夢想了。聽起來荒謬,但是值得期待……

思來想去我還是不太想撒謊,確實不太想,那就接受低薪待遇吧,這年頭誠實也是有代價的,想在這個充斥了謊言
的社會,這誠實的心態、撒謊就臉紅的心態我不知能夠保持多久,往好了說這是正直,往不好了說這叫傻、蠢、不懂得
混社會,當很多人憑藉着謊言獲得很好的待遇的時候,誠信在這個社會也逐漸變得一錢不值,這也就不難理解爲什麼在
電影“夜宴”中葛優的一句臺詞“我泱泱大國,誠信爲本”能夠引發鬨堂大笑了……

 

發佈了111 篇原創文章 · 獲贊 6 · 訪問量 18萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章