INVALID:
SELECT * FROM TableName WHERE FieldName = 'QueryString's Value'
VALID:
VALID:
SELECT * FROM TableName WHERE FieldName = 'QueryString''s Value'
SELECT * FROM TableName WHERE FieldName = 'QueryString's Value'
VALID:
SELECT * FROM TableName WHERE FieldName = 'QueryString''s Value'
double r = 5.1234;
System.out.println(r); // r is 5.1234
int decimalPlaces = 2;
BigDecimal bd = new BigDecimal(r);
// setScale is immutable
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
r = bd.doubleValue();
System.out.println(r); // r is 5.12
int n = 100;
float f = (float) (Math.round(n*100.0f)/100.0f);
DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" ); double dd2dec = new Double(df2.format(
f
)).doubleValue(); // The value of dd2dec will be 100.00
int n = 100.203;
float f = (float) (Math.round(n*100.0f)/100.0f);
DecimalFormat df2 = new DecimalFormat( "#,###,###,##0.00" ); double dd2dec = new Double(df2.format(
f
)).doubleValue(); // The value of dd2dec will be 100.20
import java.net.*; import java.io.*; public class URLUtils { public static void main(String s[]) { System.out.println(URLUtils.exists("http://www.test.com/exists.html")); System.out.println(URLUtils.exists("http://www.test.com/no_exists.html")); /* output : true false */ } public static boolean exists(String URLName){ try { HttpURLConnection.setFollowRedirects(false); // note : you may also need // HttpURLConnection.setInstanceFollowRedirects(false) HttpURLConnection con = (HttpURLConnection) new URL(URLName).openConnection(); con.setRequestMethod("HEAD"); return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } } }
The following is doing the same thing but this time we identify ourself to a proxy.
See also this HowTo.
import java.net.*; import java.io.*; import java.util.Properties; public class URLUtils { public static void main(String s[]) { System.out.println(exists("http://www.your_server.com")); System.out.println(exists("http://www.yahoo.com")); } public static boolean exists(String URLName){ try { Properties systemSettings = System.getProperties(); systemSettings.put("proxySet", "true"); systemSettings.put("http.proxyHost","proxy.mycompany.local") ; systemSettings.put("http.proxyPort", "80") ; URL u = new URL(URLName); HttpURLConnection con = (HttpURLConnection) u.openConnection(); // // it's not the greatest idea to use a sun.misc.* class // Sun strongly advises not to use them since they can // change or go away in a future release so beware. // sun.misc.BASE64Encoder encoder = new sun.misc.BASE64Encoder(); String encodedUserPwd = encoder.encode("domain\\username:password".getBytes()); con.setRequestProperty ("Proxy-Authorization", "Basic " + encodedUserPwd); con.setRequestMethod("HEAD"); System.out.println (con.getResponseCode() + " : " + con.getResponseMessage()); return (con.getResponseCode() == HttpURLConnection.HTTP_OK); } catch (Exception e) { e.printStackTrace(); return false; } } }
http://www.rgagnon.com/javadetails/java-0059.html
if (str.match("^Hello")) {
// ...
}
if (str.match("World$")) {
// ...
}