1. 列出主機內所有 Table 名稱
SELECT * FROM USER_OBJECTS
自己的小練習, 如有侵權, 被我不小心引用沒標名出處或是不想被我標示出來, 趕快跟我講, 有時候一忙會忘記看這個, 有問題或是有更好的辦法更要跟我講, 如果有什麼覺得可以更積極的, 也希望可以小力的酸我, 我玻璃心阿
總網頁瀏覽量
2017年1月25日 星期三
2017年1月24日 星期二
[JAVA] 與phpmyadmin建立連線參數
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.ResultSetMetaData;
public class ConnectiontoDB{
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL =
"jdbc:mysql://[主機位置]:3306/[資料庫名稱]?autoReconnect=true&useSSL=false";
public static void main(String args[]){
Connection connection = null;
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
System.out.println("DRIVER ERROR: "+e);}
try{
connection = DriverManager.getConnection(DATABASE_URL,"[帳號]","[密碼]");
}catch(Exception e){
System.out.println("forName: "+e);
}
}
}
加上藍色這段主要是因為不佳的時候會出現錯誤訊息
Tue Jan 24 23:17:26 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
雖然是版本問題, 但是如果改成useSSL=false就像是跳過SSL連線依樣, 其實蠻糟糕的,
所以使用的時候還是記得用useSSL= true 安全一點.
至於現在用兩個try-catch主要是讓我更知道錯誤的訊息在哪出現,
雖然蠻多餘的 ㄎㄎ. 不過這樣就知道是DRIVER錯誤還是連線錯,
雖然這次的錯誤訊息是版本問題的錯誤....
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.ResultSetMetaData;
public class ConnectiontoDB{
static final String DRIVER = "com.mysql.jdbc.Driver";
static final String DATABASE_URL =
"jdbc:mysql://[主機位置]:3306/[資料庫名稱]?autoReconnect=true&useSSL=false";
public static void main(String args[]){
Connection connection = null;
try{
Class.forName(DRIVER);
}catch(ClassNotFoundException e){
System.out.println("DRIVER ERROR: "+e);}
try{
connection = DriverManager.getConnection(DATABASE_URL,"[帳號]","[密碼]");
}catch(Exception e){
System.out.println("forName: "+e);
}
}
}
加上藍色這段主要是因為不佳的時候會出現錯誤訊息
Tue Jan 24 23:17:26 CST 2017 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
雖然是版本問題, 但是如果改成useSSL=false就像是跳過SSL連線依樣, 其實蠻糟糕的,
所以使用的時候還是記得用useSSL= true 安全一點.
至於現在用兩個try-catch主要是讓我更知道錯誤的訊息在哪出現,
雖然蠻多餘的 ㄎㄎ. 不過這樣就知道是DRIVER錯誤還是連線錯,
雖然這次的錯誤訊息是版本問題的錯誤....
[JAVA] String 字串比對
在JAVA的字串比對常用的幾個方法,
這裡不討論記憶體比對啥啥啥的問題,
單純的函式來比較.
equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)
與anotherString比較字串是否相同,
equalsIgnoreCase會針對長度與每個字元比較, 比較3種情況
1. 利用 " == ", 比較字元
2. 利用 Character.toUpperCase(char) 判斷
3. 利用 Character.toLowerCase(char) 判斷
回傳: true 非null, 且以上判斷結果都相同; 否則回傳 false.
public class string_equalsIgnoreCase{
public static void main(String args[]){
String a = "abcdefg";
String b = "ABCDEFG";
String c = "AbCdEfG";
String d = "abc";
String e = "ABC";
String f = "AbC";
String g = "";
Output:
System.out.println(a.equalsIgnoreCase(a)); true
System.out.println(a.equalsIgnoreCase(b)); true
System.out.println(a.equalsIgnoreCase(c)); true
System.out.println(a.equalsIgnoreCase(d)); false
System.out.println(a.equalsIgnoreCase(e)); false
System.out.println(a.equalsIgnoreCase(f)); false
System.out.println(a.equalsIgnoreCase(g)); false
}
}
...以要改用SyntaxHighlighter來顯示 不然這樣看得好累
equals
public boolean equals(Object anObject)
與anObject比較字串是否相同,
回傳: true 非null, 且字串與anObject相同; 否則回傳 false.
public class string_equals{
public static void main(String args[]){
String a = "abcdefg";
String b = "ABCDEFG";
String c = "AbCdEfG";
String d = "abc";
String e = "ABC";
String f = "AbC";
String g = "";
Object y = "abcdefg";
Object z = "ABCDEFG";
Output:
System.out.println(a.equals(a)); true
System.out.println(a.equals(b)); false
System.out.println(a.equals(c)); false
System.out.println(a.equals(d)); false
System.out.println(a.equals(e)); false
System.out.println(a.equals(f)); false
System.out.println(a.equals(g)); false
System.out.println(a.equals(y)); true
System.out.println(a.equals(z)); false
}
}
基本上就是利用String 裡面的每個字元的 Unicode value 做為比較依據.
如果字串比anotherString還要前面, 輸出就會出現負值.
如果字串比anotherString後面, 竟會出現正值.
如果字串都依樣, 就會出現 0.
其中出現0的前提是, compareTo會利用equals做前提比較, equals也回傳0.
其實字串比對還回牽扯到記憶體位置等等的, 那個懶得去想了. ㄎㄎ
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object)
這裡不討論記憶體比對啥啥啥的問題,
單純的函式來比較.
equalsIgnoreCase
public boolean equalsIgnoreCase(String anotherString)
與anotherString比較字串是否相同,
equalsIgnoreCase會針對長度與每個字元比較, 比較3種情況
1. 利用 " == ", 比較字元
2. 利用 Character.toUpperCase(char) 判斷
3. 利用 Character.toLowerCase(char) 判斷
回傳: true 非null, 且以上判斷結果都相同; 否則回傳 false.
public class string_equalsIgnoreCase{
public static void main(String args[]){
String a = "abcdefg";
String b = "ABCDEFG";
String c = "AbCdEfG";
String d = "abc";
String e = "ABC";
String f = "AbC";
String g = "";
Output:
System.out.println(a.equalsIgnoreCase(a)); true
System.out.println(a.equalsIgnoreCase(b)); true
System.out.println(a.equalsIgnoreCase(c)); true
System.out.println(a.equalsIgnoreCase(d)); false
System.out.println(a.equalsIgnoreCase(e)); false
System.out.println(a.equalsIgnoreCase(f)); false
System.out.println(a.equalsIgnoreCase(g)); false
}
}
...以要改用SyntaxHighlighter來顯示 不然這樣看得好累
equals
public boolean equals(Object anObject)
與anObject比較字串是否相同,
回傳: true 非null, 且字串與anObject相同; 否則回傳 false.
public class string_equals{
public static void main(String args[]){
String a = "abcdefg";
String b = "ABCDEFG";
String c = "AbCdEfG";
String d = "abc";
String e = "ABC";
String f = "AbC";
String g = "";
Object y = "abcdefg";
Object z = "ABCDEFG";
Output:
System.out.println(a.equals(a)); true
System.out.println(a.equals(b)); false
System.out.println(a.equals(c)); false
System.out.println(a.equals(d)); false
System.out.println(a.equals(e)); false
System.out.println(a.equals(f)); false
System.out.println(a.equals(g)); false
System.out.println(a.equals(y)); true
System.out.println(a.equals(z)); false
}
}
compareTo
public int compareTo(String anotherString)
利用字典序 Lexicographic order 做排列,基本上就是利用String 裡面的每個字元的 Unicode value 做為比較依據.
如果字串比anotherString還要前面, 輸出就會出現負值.
如果字串比anotherString後面, 竟會出現正值.
如果字串都依樣, 就會出現 0.
其中出現0的前提是, compareTo會利用equals做前提比較, equals也回傳0.
其實字串比對還回牽扯到記憶體位置等等的, 那個懶得去想了. ㄎㄎ
https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#equals(java.lang.Object)
訂閱:
文章 (Atom)