導航:首頁 > 專利知識 > java判斷工程名稱是否有效期

java判斷工程名稱是否有效期

發布時間:2021-08-27 12:01:25

Ⅰ 在java程序中,怎樣寫一段程序實現判斷一個表(名)是否存在

//試試這個呢
connection = DriverManager.getConnection(mySqlDbUrl, "",
"");
DatabaseMetaData meta = (DatabaseMetaData)connection.getMetaData();
ResultSet rs = meta.getTables(null, null, "AA01", null);//AA01為表名,根據你的實際情況確定
if(rs.next()){
System.err.println(true);
}else{
System.err.println(false);
}
rs.close();
connection.close();

Ⅱ java中怎麼做到判斷輸入的日期是否合法

import java.util.*;
import java.util.regex.*;
import java.text.*;

/** 這個是按照樓主的描述使用通過判斷字元驗證時間合法性 */
public class DateUtils2 {

//測試代碼 begin
public static void main(String[] s){
//以下是測試代碼
test("20099-1-1");
test("20099-100-1");
test("20099-1-100");
test("2009-1-1");
test("2009-1-31");
test("2009-2-28");
test("2009-2-29");
test("2008-2-29");
}

private static void test(String stringdate){
System.out.println("輸入[" + stringdate + "]是否合法:" + validate(stringdate));
}
//測試代碼 end

//==

/** 判斷主方法 */
public static boolean validate(String dateString){
//使用正則表達式 測試 字元 符合 dddd-dd-dd 的格式(d表示數字)
Pattern p = Pattern.compile("\\d{4}+[-]\\d{1,2}+[-]\\d{1,2}+");
Matcher m = p.matcher(dateString);
if(!m.matches()){ return false;}

//得到年月日
String[] array = dateString.split("-");
int year = Integer.valueOf(array[0]);
int month = Integer.valueOf(array[1]);
int day = Integer.valueOf(array[2]);

if(month<1 || month>12){ return false;}
int[] monthLengths = new int[]{0, 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(isLeapYear(year)){
monthLengths[2] = 29;
}else{
monthLengths[2] = 28;
}
int monthLength = monthLengths[month];
if(day<1 || day>monthLength){
return false;
}
return true;
}

/** 是否是閏年 */
private static boolean isLeapYear(int year){
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ;
}
}

Ⅲ java判斷是否是日期

樓主提出的問題有點片面,我的理解是,你是不是想判斷字元串是不是日期格式?如果已經是日期類型,那就不需要判斷了,對把。判斷給定字元串是不是日期我給你提供兩種解決思路,一種是用正則,代碼我給你寫好了。

publicbooleanisDate(Stringdate){
/**
*判斷日期格式和范圍
*/
Stringrexp="^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))";

Patternpat=Pattern.compile(rexp);

Matchermat=pat.matcher(date);

booleandateType=mat.matches();

returndateType;
}

參數就是你要判斷的日期字元串,返回布爾值;

另一種方式就是:玩字元串正則才是王道嘛!希望採納

publicbooleanisValidDate(Stringstr){
booleanconvertSuccess=true;
//指定日期格式為四位年/兩位月份/兩位日期,注意yyyy/MM/dd區分大小寫;
//如果想判斷格式為yyyy-MM-dd,需要寫成-分隔符的形式
SimpleDateFormatformat=newSimpleDateFormat("yyyy/MM/ddHH:mm");
try{

format.setLenient(false);
format.parse(str);
}catch(ParseExceptione){
//e.printStackTrace();
//如果拋出ParseException或者NullPointerException,就說明格式不對
convertSuccess=false;
}
returnconvertSuccess;
}

推薦使用正則,

Ⅳ Java判斷後綴名是否是規定有效

if(DataCheck.isHasSuffix(fileType ,allowTypes)) {
//do something...
}
/**
* 判斷類型是否包含這些
* @param fileType
* @return
*/
public static boolean isHasSuffix(String fileType,String... allowTypes) {
Boolean CanUploaded = isValid(fileType, allowTypes);
if (CanUploaded) {
System.out.println("允許上傳!");
return true;
} else {
System.out.println("禁止上傳!");
return false;
}
}
public static boolean isValid(String contentType, String... allowTypes) {
if (null == contentType || "".equals(contentType)) {
return false;
}
for (String type : allowTypes) {
if (contentType.indexOf(type) > -1) {
return true;
}
}
return false;
}

Ⅳ java判斷一個字元串是不是年份

1、首先在項目中需要引入hutool的jar包,如下圖所示。

Ⅵ java判斷字元串是否是日期

Java為了支持多語言,沒有固定的日期格式。你需要根據自己的需要指定日期格式,然後用DateFormat類或者SimpleDateFormat類來判斷是否是正確的日期格式。
下面的例子供參考。更詳細的內容可以參考javadoc。

public class DateUtil{ private static final SimpleDateFormat dateFormat = null; static { dateFormat = new SimpleDateFormat("yyyy/MM/dd"); dateFormat.setLenient(false); } public static boolean isValidDate(String s) { try { dateFormat.parse(s); return true; } catch (Exception e) { return false; } } public static String formatDate(Date d) { return dateFormat.format(d); } }

Ⅶ 在Java中怎麼判斷有效時間!!!

我記得在看ORACLE的資料庫培訓教程里有SQL語句可以把一定格式字元串直接轉成時間的。你在網上搜下相關資料:

Ⅷ java如何判斷是否為有效的年月日

年 大於 1900
月 大於0,小於13
日 if(月=1,3,5,7,8,10,12){日大於1小於等於31};
else if{月=4,6,9,11}{日大於1小於等於30};
else if(年是潤年){日大於1小於等於29};
else {日大於1小於等於28}

閏年的判斷公式如下:能被4整除且不能被100整除(year%4==0&&year&&100!=0)

Ⅸ 怎麼用JAVA語言 判斷一個文件名是否合法

什麼樣的文件名不合法?
* \ / ? 只要這樣:
char c=fileName.charAt(0); //取索引為0的字元
if( c=="*" || c=="\" || c=="/" || c=="?") System.out.println("不合法be outside the law!");
那就採用正則匹配吧

閱讀全文

與java判斷工程名稱是否有效期相關的資料

熱點內容
亞洲給水排水有版權嗎 瀏覽:397
湖北省醫療糾紛預防與處理辦法 瀏覽:230
星光創造營後勤在哪 瀏覽:581
北京辦理知識產權 瀏覽:177
交通銀行信用卡有效期是幾年 瀏覽:913
公司協議股權轉讓 瀏覽:531
啥叫擔保物權 瀏覽:60
馬鞍山到徐州的火車 瀏覽:703
羊年限定金克絲多少錢 瀏覽:573
公共基本衛生服務結核項目試題 瀏覽:896
寶雞市工商局電話號碼 瀏覽:81
基本公共衛生服務督導工作方案 瀏覽:454
信息化成果總結 瀏覽:948
債務糾紛律師費必須提供發票嗎 瀏覽:876
手機我的世界創造模式怎麼去天堂 瀏覽:716
專利代理人個人總結 瀏覽:312
工商局黨建工作述職報告 瀏覽:685
創造力閱讀理解答案 瀏覽:866
金華質監局和工商局合並 瀏覽:334
衛生院公共衛生服務考核結果 瀏覽:693