一、單例模式
餓漢模式
public class Singleton {
private Singleton(){};
private static Singleton Instance = new Singleton();
public static Singleton getInstance(){
return Instance;
}
懶漢模式
public class Singleton {
private Singleton(){}
private static class LazyHodler{
private static Singleton Instance = new Singleton();
}
public static Singleton getInstance(){
return LazyHodler.Instance;
}
}
二、數(shù)組操作
/**
* 1.獲取數(shù)組中的最大值/最小值
*/
public static int getMax(int[] arr) {
int max = arr[0];
for (int x = 1; x < arr.length; x++) {
if (arr[x] > max)
max = arr[x];
}
return max;
}
/**
* 2.給數(shù)組排序,選擇排序和冒泡排序
*/
public static void selectSort(int[] arr) {
for (int x = 0; x < arr.length - 1; x++) {
for (int y = x + 1; y < arr.length; y++) {
if (arr[x] > arr[y]) {
swap(arr, x, y);
}
}
}
}
public static void swap(int[] arr, int a, int b) {
int temp = arr[a];
arr[a] = arr[b];
arr[b] = temp;
}
public static void bubbleSort(int[] arr) {
for (int x = 0; x < arr.length - 1; x++) {
for (int y = 0; y < arr.length - x - 1; y++)//-x:讓每一次比較的元素減少,-1:避免角標越界。
{
if (arr[y] < arr[y + 1]) {
swap(arr, y, y + 1);
}
}
}
}
/**
* 3.對給定的數(shù)組進行反轉
*/
public static void reverseArray(int[] arr) {
for (int start = 0, end = arr.length - 1; start < end; start++, end--) {
swap(arr, start, end);
}
}
/**
* 4.數(shù)組的查找操作,
*/
public static int getIndex(int[] arr, int key) {
for (int x = 0; x < arr.length; x++) {
if (arr[x] == key)
return x;
}
return -1;
}
//二分法查找,先排序
public static int halfSearch(int[] arr, int key) {
int min, max, mid;
min = 0;
max = arr.length - 1;
mid = (max + min) / 2;
while (arr[mid] != key) {
if (key > arr[mid])
min = mid + 1;
else if (key < arr[mid])
max = mid - 1;
if (min > max)
return -1;
mid = (max + min) / 2;
}
return mid;
}
//保留小數(shù)點,在四舍五入后
public class TestMath {
public static void main(String[] args) {
/*
Random r = new Random();
for(int x=0; x<10; x++)
{
//int d = (int)(Math.random()*10+1);
int d = r.nextInt(10)+1;
sop(d);
}
*/
saveTwo(12.3456, 2, true);//12.34
}
public static void saveTwo(double d, int scale, boolean isRound) {
double base = Math.pow(10, scale);
double num = isRound ? Math.round(d * base) / base : ((int) (d * base)) / base;
sop("num=" + num);
/*
double d1 = d*100;
sop("d1="+d1);
d1 = d1+0.5;
double d2 = (int)d1;
sop("d2="+d2);
double d3 = d2/100;
sop("d3="+d3);
*/
}
public static void show() {
double d = Math.ceil(16.34);//ceil返回大于指定數(shù)據(jù)的最小整數(shù)。
double d1 = Math.floor(12.34);//floor返回小于指定數(shù)據(jù)的最大整數(shù)。
long l = Math.round(12.54);//四舍五入
sop("d=" + d);
sop("d1=" + d1);
sop("l=" + l);
double d2 = Math.pow(2, 3);
sop("d2=" + d2);
}
public static void sop(Object obj) {
System.out.println(obj);
}
}
三、字符串操作
/*基本數(shù)據(jù)類型對象包裝類。
byte Byte
short short
int Integer
long Long
boolean Boolean
float Float
double Double
char Character
基本數(shù)據(jù)類型轉成字符串。
基本數(shù)據(jù)類型+""
包裝類.toString(基本數(shù)據(jù)類型值);
如: Integer.toString(34);//將34整數(shù)變成"34";
字符串轉成基本數(shù)據(jù)類型。
xxx a = Xxx.parseXxx(String);
int a = Integer.parseInt("123");
double b = Double.parseDouble("12.23");
boolean b = Boolean.parseBoolean("true");
Integer i = new Integer("123");
int num = i.intValue();
/**
* 將字符串變成數(shù)組
* 對數(shù)組反轉,將數(shù)組變成字符串
*/
public static String reverseString(String s, int start, int end) {
//字符串變數(shù)組。
char[] chs = s.toCharArray();
//反轉數(shù)組。
reverse(chs, start, end);
//將數(shù)組變成字符串。
return new String(chs);
}
private static void reverse(char[] arr, int x, int y) {
for (int start = x, end = y - 1; start < end; start++, end--) {
swap(arr, start, end);
}
}
private static void swap(char[] arr, int x, int y) {
char temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
/**
* 去除字符串兩端空格
*/
public static String myTrim(String str) {
int start = 0, end = str.length() - 1;
while (start <= end && str.charAt(start) == ' ')
start++;
while (start <= end && str.charAt(end) == ' ')
end--;
return str.substring(start, end + 1);
}
/**
* 子串在整串中出現(xiàn)的次數(shù)。
*/
private static int getCount(String str, String ref) {
int count = 0;
while (str.contains(ref)) {
str = str.substring(str.indexOf(ref) + ref.length());
count++;
}
return count;
}
/**
* 對字符串中字符進行自然順序排序。
* 思路:字符串變成字符數(shù)組,對數(shù)組排序,選擇,冒泡,Arrays.sort(),將排序后的數(shù)組變成字符串。
*/
/**
* 要求對字符串中的數(shù)值進行排序。生成一個數(shù)值從小到大新字符串。
* 思路:
* 1,將字符串切割。變成字符串數(shù)組。
* 2,將字符串數(shù)組轉成int數(shù)組。
* 3,int數(shù)組排序。
* 4,將int數(shù)組變成字符串。
*/
public static String numberStringSort(String str) {
String[] arr = splitString(str);
int[] nums = toIntArray(arr);
Arrays.sort(nums);
return intArraytoString(nums);
}
private static String[] splitString(String str) {
return str.split(" ");
}
private static int[] toIntArray(String[] arr) {
int[] nums = new int[arr.length];
for (int x = 0; x < arr.length; x++) {
nums[x] = Integer.parseInt(arr[x]);
}
return nums;
}
private static String intArraytoString(int[] arr) {
StringBuilder sb = new StringBuilder();
for (int x = 0; x < arr.length; x++) {
if (x != arr.length - 1)
sb.append(arr[x] + " ");
else
sb.append(arr[x]);
}
return sb.toString();
}
/**
* 獲取兩個字符串中最大相同子串。第一個動作:將短的那個串進行長度一次遞減的子串打印
* "abcwerthelloyuiodef" "cvhellobnm"
* 思路:將短的那個子串按照長度遞減的方式獲取到,將每獲取到的子串去長串中判斷是否包含,如果包含,已經找到!
*/
public static String getMaxSubString(String s1, String s2) {
String max = "", min = "";
max = (s1.length() > s2.length()) ? s1 : s2;
min = (max == s1) ? s2 : s1;
for (int x = 0; x < min.length(); x++) {
for (int y = 0, z = min.length() - x; z != min.length() + 1; y++, z++) {
String temp = min.substring(y, z);
//sop(temp);
if (max.contains(temp))//if(s1.indexOf(temp)!=-1)
return temp;
}
}
return "";
}
四、集合操作
/*Collection定義了集合框架的共性功能。
1,添加
add(e);
addAll(collection);
2,刪除
remove(e);
removeAll(collection);
clear();
3,判斷。
contains(e);
isEmpty();
4,獲取
iterator();
size();
5,獲取交集。
retainAll();
6,集合變數(shù)組。
toArray();
1,add方法的參數(shù)類型是Object。以便于接收任意類型對象。
2,集合中存儲的都是對象的引用(地址)
什么是迭代器呢?
其實就是集合的取出元素的方式。
如同抓娃娃游戲機中的夾子。
迭代器是取出方式,會直接訪問集合中的元素。
所以將迭代器通過內部類的形式來進行描述。
通過容器的iterator()方法獲取該內部類的對象。
*/
- List
/**
* Created by joshul on 2017/3/6.
* ArrayList 數(shù)組形式訪問List鏈式集合數(shù)據(jù),元素可重復,訪問元素較快 數(shù)組
* LinkedList 鏈表方式的List鏈式集合,元素可重復,元素的插入刪除較快 雙向鏈表
*/
public class TestList {
public static void main(String[] args) {
}
/**
* ArrayList 數(shù)組形式訪問List鏈式集合數(shù)據(jù),元素可重復,訪問元素較快 數(shù)組
* @param al
* @return
*/
public static ArrayList singleElement(ArrayList al) {
//定義一個臨時容器。
ArrayList newAl = new ArrayList();
Iterator it = al.iterator();
while(it.hasNext())
{
Object obj = it.next();
if(!newAl.contains(obj))
newAl.add(obj);
}
return newAl;
}
}
- Set
/**
* Created by joshul on 2017/3/6.
* Set的核心概念就是集合內所有元素不重復。在Set這個子接口中沒有在Collection特別實現(xiàn)什么額外的方法,應該只是定義了一個Set概念。
* 下面我們來看Set的幾個常用的實現(xiàn)HashSet、LinkedHashSet、TreeSet
* <p>
* HashSet 無序的、無重復的數(shù)據(jù)集合 基于HashMap
* LinkedSet 維護次序的HashSet 基于LinkedHashMap
* TreeSet 保持元素大小次序的集合,元素需要實現(xiàn)Comparable接口 基于TreeMap
*/
public class TestSet {
/**
* "90 -7 0 18 2 45 4",將字符串中的數(shù)值進行排序。使用TreeSet完成。
* 將字符串切割,可以將這些對象存入TreeSet集合。因為TreeSet自身具備排序功能。
*/
public static void main(String[] args) {
String str = "90 -7 0 18 2 45 4";
String[] arr = str.split(" ");
TreeSet ts = new TreeSet();
for (int x = 0; x < arr.length; x++) {
//ts.add(new Integer(arr[x]));
ts.add(Integer.parseInt(arr[x]));//
}
System.out.println(ts);
}
}
- Mep
public class TestMap {
public static void main(String[] args) {
String s= charCount("ak+abAf1c,dCkaAbc-defa");
System.out.println(s);
}
/**
* "sdfgzxcvasdfxcvdf"獲取該字符串中的字母出現(xiàn)的次數(shù)。
* 希望打印結果:a(1)c(2).....
* 思路:
* 1,將字符串轉換成字符數(shù)組。因為要對每一個字母進行操作。
* 2,定義一個map集合,因為打印結果的字母有順序,所以使用treemap集合
* 3,遍歷字符數(shù)組。
* 將每一個字母作為鍵去查map集合。
* 如果返回null,將該字母和1存入到map集合中。
* 如果返回不是null,說明該字母在map集合已經存在并有對應次數(shù)。那么就獲取該次數(shù)并進行自增。,然后將該字母和自增后的次數(shù)存入到map集合中。覆蓋調用原理鍵所對應的值。
* 4,將map集合中的數(shù)據(jù)變成指定的字符串形式返回。
*/
public static String charCount(String str) {
char[] chs = str.toCharArray();
TreeMap<Character, Integer> tm = new TreeMap<Character, Integer>();
int count = 0;
for (int x = 0; x < chs.length; x++) {
if (!(chs[x] >= 'a' && chs[x] <= 'z' || chs[x] >= 'A' && chs[x] <= 'Z'))
continue;
Integer value = tm.get(chs[x]);
if (value != null)
count = value;
count++;
tm.put(chs[x], count);//直接往集合中存儲字符和數(shù)字,為什么可以,因為自動裝箱。
count = 0;
}
//System.out.println(tm);
StringBuilder sb = new StringBuilder();
Set<Map.Entry<Character, Integer>> entrySet = tm.entrySet();
Iterator<Map.Entry<Character, Integer>> it = entrySet.iterator();
while (it.hasNext()) {
Map.Entry<Character, Integer> me = it.next();
Character ch = me.getKey();
Integer value = me.getValue();
sb.append(ch + "(" + value + ")");
}
return sb.toString();
}
}
四、IO操作
/**
* Created by joshul on 2017/3/1.
* IO流用來處理設備之間的數(shù)據(jù)傳輸
* Java對數(shù)據(jù)的操作是通過流的方式
* Java用于操作流的對象都在IO包中
* 流按操作數(shù)據(jù)分為兩種:字節(jié)流與字符流
* 流按流向分為:輸入流,輸出流。
* 字節(jié)流的抽象基類: InputStream ,OutputStream。
* 字符流的抽象基類: Reader , Writer。
* InputStream的子類FileInputStream。
* Reader的子類FileReader。
* IO程序的書寫:
* 導入IO包中的類
* 進行IO異常處理
* 在finally中對流進行關閉
* <p>
* 字符流的緩沖區(qū)
* 緩沖區(qū)的出現(xiàn)提高了對數(shù)據(jù)的讀寫效率。
* 對應類: BufferedWriter, BufferedReader
* 緩沖區(qū)要結合流才可以使用,在流的基礎上對流的功能進行了增強。
* <p>
* 裝飾設計模式:對原有類進行了功能的改變,增強。
*/
public class Io {
public static void main(String[] args) {
getTime();
}
/**
* 獲取現(xiàn)在時間
*/
public static void getTime() {
Date d = new Date();
System.out.println(d);//打印的時間看不懂,希望有些格式。
//將模式封裝到SimpleDateformat對象中。
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日E hh:mm:ss");
//調用format方法讓模式格式化指定Date對象。
String time = sdf.format(d);
System.out.println("time=" + time);
long l = System.currentTimeMillis();
Date d1 = new Date(l);
System.out.println("d1:" + d1);
}
/**
* 讀取一個.java文件,并打印在控制臺上。
*/
public static void readJava() {
FileReader fr = null;
try {
fr = new FileReader("DateDemo.java");
char[] buf = new char[1024];
int num = 0;
while ((num = fr.read(buf)) != -1) {
System.out.print(new String(buf, 0, num));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 演示對已有文件的數(shù)據(jù)續(xù)寫。
*/
public static void readFile() {
FileWriter fw = null;
try {
//傳遞一個true參數(shù),代表不覆蓋已有的文件。并在已有文件的末尾處進行數(shù)據(jù)續(xù)寫。
fw = new FileWriter("demo.txt", true);
fw.write("nihao\r\nxiexie");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* FileWriter
*/
public static void fileWriter() {
FileWriter fw = null;
try {
//創(chuàng)建一個FileWriter對象。該對象一被初始化就必須要明確被操作的文件。
//而且該文件會被創(chuàng)建到指定目錄下。如果該目錄下已有同名文件,將被覆蓋。
//其實該步就是在明確數(shù)據(jù)要存放的目的地。
fw = new FileWriter("demo.txt");
//調用write方法,將字符串寫入到流中。
fw.write("abcde");
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
//刷新流對象中的緩沖中的數(shù)據(jù)。
//將數(shù)據(jù)刷到目的地中。
//fw.flush();
//關閉流資源,但是關閉之前會刷新一次內部的緩沖中的數(shù)據(jù)。
//將數(shù)據(jù)刷到目的地中。
//和flush區(qū)別:flush刷新后,流可以繼續(xù)使用,close刷新后,會將流關閉。
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
/*//傳遞一個true參數(shù),代表不覆蓋已有的文件。并在已有文件的末尾處進行數(shù)據(jù)續(xù)寫。
FileWriter fw = new FileWriter("demo.txt",true);
fw.write("nihao\r\nxiexie");
fw.close();*/
}
}
**
* Created by joshul on 2017/3/6.
* 字符流:FileReader FileWriter。/BufferedReader BufferedWriter
* 字節(jié)流:InputStream OutputStream
* 需求,想要操作圖片數(shù)據(jù)。這時就要用到字節(jié)流。
*/
public class TestBuffer {
public static void main(String[] args){
}
public static void BufferedReader() {
FileReader fr = null;
BufferedReader bufr = null;
try {
//創(chuàng)建一個讀取流對象和文件相關聯(lián)。
fr = new FileReader("buf.txt");
//為了提高效率。加入緩沖技術。將字符讀取流對象作為參數(shù)傳遞給緩沖對象的構造函數(shù)。
bufr = new BufferedReader(fr);
String line = null;
while ((line = bufr.readLine()) != null) {
System.out.print(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bufr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
/*public static void BufferedWriter() {
//創(chuàng)建一個字符寫入流對象。
FileWriter fw = new FileWriter("buf.txt");
//為了提高字符寫入流效率。加入了緩沖技術。
//只要將需要被提高效率的流對象作為參數(shù)傳遞給緩沖區(qū)的構造函數(shù)即可。
BufferedWriter bufw = new BufferedWriter(fw);
for(int x=1; x<5; x++)
{
bufw.write("abcd"+x);
bufw.newLine();
bufw.flush();
}
//記住,只要用到緩沖區(qū),就要記得刷新。
//bufw.flush();
//其實關閉緩沖區(qū),就是在關閉緩沖區(qū)中的流對象。
bufw.close();
}*/
}
四、SQL題
1.寫一個sql將表TEST_A(ID,NAME,CODE)中重復次數(shù)大于2的NAME值打印出來
select NAME from TEST_A
where NAME in(select NAME from TEST_A group by NAME having count(NAME)>2);
2.用一條SQL 語句 查詢出每門課都大于80 分的學生姓名student_tb
name kecheng fenshu
張三 語文 81
張三 數(shù)學 75
select name from student_tb where fenshu in(select fenshu from student_tb group by having min(fenshu)>80);
3.學生表 如下:student_tb
自動編號 學號 姓名 課程編號 課程名稱 分數(shù)
1 2005001 張三 0001 數(shù)學 69
2 2005002 李四 0001 數(shù)學 89
3 2005001 張三 0001 數(shù)學 69
刪除除了自動編號不同, 其他都相同的學生冗余信息
delete from student_tb where 自動編號 not in(select min(自動編號) from student_tb group by 學號,姓名,課程編號,課程名稱,分數(shù))
4.一個叫 team 的表,里面只有一個字段name, 一共有4 條紀錄,分別是a,b,c,d, 對應四個球隊,現(xiàn)在四個球隊進行比賽,用一條sql 語句顯示所有可能的比賽組合.
select a.name,b.name from student2 a, student2 b
where a.name<b.name;
5.請用SQL 語句實現(xiàn):從TestDB 數(shù)據(jù)表中查詢出所有月份的發(fā)生額都比101 科目相應月份的發(fā)生額高的科目.請注意:TestDB 中有很多科目,都有1 -12 月份的發(fā)生額.
AccID :科目代碼,Occmonth :發(fā)生額月份,DebitOccur :發(fā)生額.
數(shù)據(jù)庫名:JcyAudit,數(shù)據(jù)集:Select * from TestDB
select a.* from TestDB as a,(select Occmonth,max(DebitOccur) Debit101ccur from TestDB where AccID= '101' group by Occmonth) b
where a.Occmonth = b.Occmonth and a.DebitOccur > b.Debit101ccur
6. 面試題:怎么把這樣一個表兒
year month amount
1991 1 1.1
1991 2 1.2
1991 3 1.3
1991 4 1.4
1992 1 2.1
1992 2 2.2
1992 3 2.3
1992 4 2.4
查成這樣一個結果
year m1 m2 m3 m4
1991 1.1 1.2 1.3 1.4
1992 2.1 2.2 2.3 2.4
select year,(select amount from table_aa m where month = 1 and table_aa.year = m.year) as m1,() as m2,() as m3 from table_aa
group by year;
7. 說明:復制表( 只復制結構, 源表名:a 新表名:b)
select * into b from a where 1<>1 (where1=1,拷貝表結構和數(shù)據(jù)內容)
7. 說明:拷貝表( 拷貝數(shù)據(jù), 源表名:a 目標表名:b)
insert into b(a, b, c) select d,e,f from a;
8. 說明:顯示文章.提交人和最后回復時間
select a.title a.name b.adddate from table a ,(select max(adddate) adddate from table where a.title = table.title) b
9. 說明:外連接查詢( 表名1 :a 表名2 :b)
select a.a,a.b,a.c,b.c,b.d,b.f from a left outer join b on a.a = b.c
10. 說明:日程安排提前五分鐘提醒
select * from 日程安排 where datediff('minute',f 開始時間,getdate())>5
11. 說明:兩張關聯(lián)表,刪除主表中已經在副表中沒有的信息
Delete from info where not exists (select * from infobz where info.infid=infobz.infid )
12. 有兩個表A 和B ,均有key 和value 兩個字段,如果B 的key 在A 中也有,就把B 的value 換為A 中對應的value
這道題的SQL 語句怎么寫?
update b set b.value=(select a.value from a where a.key=b.key) where b.id in(select b.id from b,a where b.key=a.key);
SQL面試題
1 觸發(fā)器的作用?
答:觸發(fā)器是一中特殊的存儲過程,主要是通過事件來觸發(fā)而被執(zhí)行的。它可以強化約束,來維護數(shù)據(jù)的完整性和一致性,可以跟蹤數(shù)據(jù)庫內的操作從而不允許未經許可的更新和變化。
可以聯(lián)級運算。如,某表上的觸發(fā)器上包含對另一個表的數(shù)據(jù)操作,而該操作又會導致該表觸發(fā)器被觸發(fā)。
2 什么是存儲過程?用什么來調用?
答:存儲過程是一個預編譯的 SQL 語句,優(yōu)點是允許模塊化的設計,就是說只需創(chuàng)建一次,以后在該程序中就可以調用多次。如果某次操作需要執(zhí)行多次 SQL ,
使用存儲過程比單純 SQL 語句執(zhí)行要快。可以用一個命令對象來調用存儲過程。
3 索引的作用?和它的優(yōu)點缺點是什么?
答:索引就一種特殊的查詢表,數(shù)據(jù)庫的搜索引擎可以利用它加速對數(shù)據(jù)的檢索。它很類似與現(xiàn)實生活中書的目錄,不需要查詢整本書內容就可以找到想要的數(shù)據(jù)。索引可以是唯一的,
創(chuàng)建索引允許指定單個列或者是多個列。缺點是它減慢了數(shù)據(jù)錄入的速度,同時也增加了數(shù)據(jù)庫的尺寸大小。
3 什么是內存泄漏?
答:一般我們所說的內存泄漏指的是堆內存的泄漏。堆內存是程序從堆中為其分配的,大小任意的,使用完后要顯示釋放內存。當應用程序用關鍵字 new 等創(chuàng)建對象時,就從堆中為它分配一塊內存,
使用完后程序調用 free 或者 delete 釋放該內存,否則就說該內存就不能被使用,我們就說該內存被泄漏了。
4 維護數(shù)據(jù)庫的完整性和一致性,你喜歡用觸發(fā)器還是自寫業(yè)務邏輯?為什么?
答:我是這樣做的,盡可能使用約束,如 check, 主鍵,外鍵,非空字段等來約束,這樣做效率最高,也最方便。其次是使用觸發(fā)器,這種方法可以保證,
無論什么業(yè)務系統(tǒng)訪問數(shù)據(jù)庫都可以保證數(shù)據(jù)的完整新和一致性。最后考慮的是自寫業(yè)務邏輯,但這樣做麻煩,編程復雜,效率低下。
5 什么是事務?什么是鎖?
答:事務就是被綁定在一起作為一個邏輯工作單元的 SQL 語句分組,如果任何一個語句操作失敗那么整個操作就被失敗,以后操作就會回滾到操作前狀態(tài),或者是上有個節(jié)點。
為了確保要么執(zhí)行,要么不執(zhí)行,就可以使用事務。要將有組語句作為事務考慮,就需要通過 ACID 測試,即原子性,一致性,隔離性和持久性。
鎖:在所以的 DBMS 中,鎖是實現(xiàn)事務的關鍵,鎖可以保證事務的完整性和并發(fā)性。與現(xiàn)實生活中鎖一樣,它可以使某些數(shù)據(jù)的擁有者,在某段時間內不能使用某些數(shù)據(jù)或數(shù)據(jù)結構。當然鎖還分級別的。
6 什么叫視圖?游標是什么?
答:視圖是一種虛擬的表,具有和物理表相同的功能。可以對視圖進行增,改,查,操作,試圖通常是有一個表或者多個表的行或列的子集。對視圖的修改不影響基本表。它使得我們獲取數(shù)據(jù)更容易,相比多表查詢。
游標:是對查詢出來的結果集作為一個單元來有效的處理。游標可以定在該單元中的特定行,從結果集的當前行檢索一行或多行。可以對結果集當前行做修改。一般不使用游標,但是需要逐條處理數(shù)據(jù)的時候,游標顯得十分重要。
題目補充
1.寫一個sql將表TEST_A(ID,NAME,CODE)中重復次數(shù)大于2的NAME值打印出來(15)
select NAME from TEST_A
where NAME in(select NAME from TEST_A group by NAME having count(NAME)>2);
2.寫一段代碼獲取結構 List<Map<String,String>>中各個Map,并通過System.out.println()打印出來(15)
/**
* 將指定的 結構為 List<Map<String,String>>的參數(shù) 通過System.out.println()打印出來
* 格式:"鍵名:鍵值"
* @param List<Map<String,String>>
*
*/
public void printOut(List<Map<String,String>>){
List<Map<String,Object>> list= List<Map<String,String>>
for (int i=0;i<list.size(),i++)
{
Map map=(Map)list.get(i);
Iterator iterator = map.keySet().iterator();
while (iterator.hasNext())
{
String key = (String) iterator.next();
Object object = map.get(key);
}
}
}
3.有類似這樣的一串字符"abcddeffx.asre-321!assra..",請實現(xiàn)以下方法將字符串各個字符的出現(xiàn)的次數(shù)統(tǒng)計出來
/**
* 將指定的 結構為 List<Map<String,String>>的參數(shù) 通過System.out.println()打印出來
* 格式:"鍵名:鍵值"
* @param List<Map<String,String>>
* @return Map<字符,出現(xiàn)的次數(shù)>
*/
public Map<Character,Integer> staticCharcnt(String str){
}
4.在一個文本文件(文件大小不超過2k)中存放了很多以空格分隔的英語單詞,請寫一段偽代碼或用文字描述來實現(xiàn),已得到沒有重復的、且按字典順序排序的所有單詞(20分)
首先實現(xiàn)做一個SortedMap,這個Map的Comparator是根據(jù)字母順序排列的一個規(guī)則.
5.請用javascript語言解析如下json對象,取出對象中所有數(shù)據(jù)或將其顯示在頁面上。(15)
var user = {
"username" : "andy",
"age" : 25,
"info" : {"tell":"123","cellphone":"13766"}
"address" : [
{"city":"北京建國門大街"}
{"city":"天津海泰信息廣場"}
]
}
<table border="1">
<tr>
<td>user.username</td>
<td>user.age</td>
<td>user.info.tell</td>
<td>(user.address[0].city</td>
<td>user.address[1].city</td>
</tr>
</table>
6.在項目中一導入jquery1.7庫,請實現(xiàn)用jquery查找下列表格的第二行第三列的值。(15)
<table id= "tab">
<tbody>
<tr>
<td>第一行第一列</td>
<td>第一行第二列</td>
<td>第一行第三列</td>
<td>第一行第四列</td>
</tr>
<tr>
<td>第二行第一列</td>
<td>第二行第二列</td>
<td>第二行第三列</td>
<td>第二行第四列</td>
</tr>
</tbody>
</table>
$('#tab tr').eq(1).find('td').eq(2)