2018年11月29日星期四java
先用mysql客戶端鏈接主機mysql數據庫,建立一個數據庫ykdb,調整程序能夠操做mysql數據庫mysql
轉到bin路徑,複製鏈接mysql數據庫的jar包到bin路徑,運行程序 java -cp ./ mysql-connector-java-5.1.12-bin.jar;. yksqllinux
yksql>建立一張表yktbl(id int auto_increment primary key,idb char(10) )算法
yksql>增長一個日期字段rqsql
yksql>增長數據 insert into yktbl(idb,rq) values( 填空 )數據庫
yksql>顯示數據編程
作完後在電腦中找到你建立的數據庫所在的文件夾數組
數據庫服務器
單機數據庫:access sqlite。。。網絡
網絡數據庫: Oracle mysql sqlserver sybase informix db2.。。。。。
企業用的都是服務器版數據庫,必定在某個端口偵聽,數據庫必定對應系統的某個文件,使用數據庫必定須要用戶 和口令
使用標準SQL和數據庫進行交流,每一個數據庫還有在標準SQL基礎上擴展的可編程的部分,這塊是不同的
讓程序能夠操做Sqlserver數據庫須要一個sqlserver數據庫、操做sqlserver的jar包,而後調整代碼中Class.forName(驅動類的名字)調整getConnection中URL、USER、PASS
不須要修改咱們的程序,就能操做全部的數據庫,怎麼作?
方法一:
String sDriver=null,sUrl=null,sUser=null,sPwd=null;
switch(dbtype){
case 「oracle」:
sDriver=」oracle……」; sUrl=」oracleurl」; sUser=」scott」;sPwd=」tiger」;
break;
case 「mysql」:
sDriver=」mysql……」; sUrl=」mysqlurl」; sUser=」root」;sPwd=」」;
break;
…….
defautl:
break;
}
Class.forName(sDriver);
Connection conn=DriverManager.getConnection(sUrl,sUser,sPwd);
方法二:
用一個文件配置driver、url、user、paas信息
怎麼讀properties文件?
class read {
public static void main(String... args) {
System.out.println(System.getProperty("user.dir"));
}
}
在命令行不一樣位置運行這個程序( )
import java.io.FileInputStream;
import java.io.FileNotFoundException;
class read {
public static void main(String... args) throws FileNotFoundException {
String sPath=System.getProperty("user.dir");
sPath=sPath+"/db.properties";
new FileInputStream(sPath);
}
}
在命令行運行(注意有包要帶上包名稱)不要看到異常
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Properties;
class read {
public static void main(String... args) {
String sPath=System.getProperty("user.dir");
sPath=sPath+"/db.properties";
try {
FileInputStream fin= new FileInputStream(sPath);
Properties prop=new Properties();
prop.load(fin);
System.out.println(prop.getProperty("driver"));
System.out.println(prop.getProperty("url"));
System.out.println(prop.getProperty("user"));
System.out.println(prop.getProperty("pass"));
System.out.println(prop.getProperty("key"));
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
在命令行運行程序( )
unix/linux:什麼是硬連接、軟連接?
sql:什麼是外鏈接、內鏈接?
能夠放那些修飾符 class ClsName{
能夠放那些修飾符 class InnerCls{
}
}
abstract class ClsName {
abstract void aaa();
}
interface ICls {
}
class TestI {
public static void main(String[] args) {
new ClsName();
new ICls();
}
}
什麼錯誤,爲何?
class ClsName {
class InnerCls {
void test() {
System.out.println(InnerCls.class);
}
}
}
class TestI {
public static void main(String[] args) {
// 怎麼調用test()函數
}
}
找找生成的class文件,看內部類是怎麼表示的
class ClsName {
static class InnerCls {
void test() {
System.out.println(InnerCls.class);
}
}
}
class TestI {
public static void main(String[] args) {
// 怎麼調用test()函數
}
}
匿名內部類
interface ICls{
void abc();
}
class TestI {
public static void main(String[] args) {
new ICls() {
public void abc() {
// TODO Auto-generated method stub
}
};
}
}
程序=數據結構+算法(求解某個問題的過程或方法)
程序由 數據 及 處理數據的函數組成
鏈表(單鏈表、雙鏈表)
哈希表(key鍵---value值)
無論什麼數據結構,數據最終在內存存儲形式:順序存儲、鏈式存儲
new String[10]
new String() …… new String()
class ListData {
int a;
String b;
public ListData() {
}
public ListData(int a, String b) {
this.a = a;
this.b = b;
}
public int getA() {
return a;
}
public void setA(int a) {
this.a = a;
}
public String getB() {
return b;
}
public void setB(String b) {
this.b = b;
}
ListData next;//定義一個引用,記錄下一個節點地址
public ListData getNext() {
return next;
}
public void setNext(ListData next) {
this.next = next;
}
}
class ds{
public static void main(String[] args) {
ListData lst[]=new ListData[10];//順序
lst[0]=new ListData();
ListData head=null;
head=new ListData(100, "abc");
ListData yly= new ListData(200, "bca");
head.setNext(yly);
yly.setNext(new ListData(300, "cab"));
//怎麼經過head遍歷每條數據
while (head!=null) {
System.out.println(head);
head=head.getNext();
}
}
}
運行結果( )
在ListData重寫toString()
public String toString() {
// TODO Auto-generated method stub
return "a="+a+",b="+b;
}
再運行程序
C++: STL standard template libaray
java: collections framework
ArrayList 和 LinkedList區別?
順序存儲 鏈式存儲
class ds{
public static void main(String[] args) {
Map<String,Integer> map=new HashMap<String, Integer>();
System.out.println(map.size());
System.out.println(map.get("yangkang"));
}
}
運行結果( )
class ds {
public static void main(String[] args) {
Map<String, Integer> map = new HashMap<String, Integer>();
String str = "abc cba abc nba cba";
String[] str2 = str.split(" ");
System.out.println(str2.length);
for (int i = 0; i < str2.length; i++) {
Integer v = map.get(str2[i]);
if (v == null) {
map.put(str2[i], 1);
} else {
map.put(str2[i], v + 1);
}
}
Set<String> kSet=map.keySet();
for (String string : kSet) {
System.out.println(string+":"+map.get(string));
}
}
}
運行結果( )
實踐(2018年11月29日星期四):
1)會員表(memid memname)
會員消費表(id 自動增加字段 消費日期xfrq 消費金額xfje 會員 memid)
統計2018年10月全部會員消費金額、顯示會員號、會員名稱、消費金額,並按消費金額降序
方法一
查詢有消費
union
沒有消費的;
方法二
左或右鏈接查詢;
2修改操做數據庫的程序,將鏈接數據庫的相關信息寫到db.properties
3 寫一個函數:統計一個字符串中每一個數字的個數
作的快的繼續
4 怎麼讓程序能執行
insert into tbl(fld1,fld2) select f1,f2 from tbl2 這種格式sql語句
能執行 desc 表名 查看錶結構(兩我的合做完成)
5 oracle/mysql如何對數據進行分頁顯示(獨立完成)
6 linux實如今凌晨一點自動備份指定文件夾(好比/home)的全部信息(備份文件名稱:備份時間.tar.gz ,好比201811291239.tar.gz),並遠程複製到另一臺linux電腦(兩我的合做完成)
提示:寫一個腳本(獲取時間、tar命令備份、遠程複製),而後配置任務計劃(crontab)指定執行腳本的時間,遠程複製需解決免密登陸問題
7 找一個操做數據庫的GUI客戶端,能夠操做任何數據庫