打開Eclipse或MyEclipse,選中你的項目,選擇上面菜單欄的Search(也可以使用IDE的快捷鍵ctrl+H打開),輸入你要查找的關(guān)鍵字,就能整個項目,甚至整個工作空間的查找,控制臺旁邊的Search標(biāo)簽頁會顯示查找結(jié)果。

創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的湟源網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.SimpleFormatter;
public class DateTest {
/**
* 判斷是否在同一個月
* @param startDate yyyy-MM-dd
* @param endDate yyyy-MM-dd
* @return false:不在同一個月內(nèi),true在同一個月內(nèi)
*/
public static boolean isMonth(String startDate,String endDate){
if(margin(startDate, endDate)31){
return false;
}
int startMonth = Integer.parseInt(startDate.substring(5, 7));
int endMonth = Integer.parseInt(endDate.substring(5, 7));
if(startMonth==endMonth){
return true;
}else{
return false;
}
}
/**
* 計算開始日期和結(jié)束日期差
* @param startDate yyyy-MM-dd
* @param endDate yyyy-MM-dd
* @return
*/
private static int margin(String startDate,String endDate){
ParsePosition pos = new ParsePosition(0);
ParsePosition pos2 = new ParsePosition(0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Date ds = sdf.parse(startDate, pos);
Date de = sdf.parse(endDate, pos2);
long l = de.getTime()-ds.getTime();
int margin = (int)(l/24*60*60*1000);
return margin;
}
/**
* main方法測試
* @param args
*/
public static void main(String[] args) {
System.out.println(DateTest.isMonth("2014-10-17", "2014-10-25"));
System.out.println(DateTest.isMonth("2014-10-17", "2014-12-25"));
}
}
import java.sql.Connection。
import java.sql.DriverManager; ?
import java.sql.PreparedStatement; ?
import java.sql.ResultSet; ?
import java.sql.SQLException;
import javax.naming.Context; ?
import javax.naming.InitialContext; ?
import javax.naming.NamingException; ?
import javax.sql.DataSource;
public class DBCon {
//數(shù)據(jù)庫驅(qū)動對象
public static final String DRIVER="oracle.jdbc.driver.OracleDriver";
//數(shù)據(jù)庫連接地址(數(shù)據(jù)庫名)
public static final String URL="jdbc:oracle:thin:@localhost:1521:orcl";
//登陸名
public static final String USER="FM";
//登陸密碼
public static final String PWD="FM";
//創(chuàng)建數(shù)據(jù)庫連接對象
private Connection con=null;
//創(chuàng)建數(shù)據(jù)庫預(yù)編譯對象
private PreparedStatement ps=null;
//創(chuàng)建結(jié)果集
private ResultSet rs=null;
//創(chuàng)建數(shù)據(jù)源對象
public static DataSource source=null;
// ?//靜態(tài)代碼塊 ?
// ?static{ ?
// ?
// ? ? ?//初始化配置文件context ?
// ? ? ?try { ?
// ? ? ? ? ?Context context=new InitialContext(); ?
// ? ? ? ? ?source=(DataSource)context.lookup("java:comp/env/jdbc/webmessage"); ?
// ? ? ?} catch (Exception e) { ?
// ? ? ? ? ?// TODO Auto-generated catch block ?
// ? ? ? ? ?e.printStackTrace(); ?
// ? ? ?} ?
// ?
// ?
// ?}
/**
* 獲取數(shù)據(jù)庫連接
*/
public Connection getCon(){
try {
Class.forName(DRIVER);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
con=DriverManager.getConnection(URL,USER,PWD);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
} ?
// ?/** ?
// ? * 獲取數(shù)據(jù)庫連接 ?
// ? */ ?
// ?public Connection getCon(){ ?
// ?
// ? ? ?try { ?
// ? ? ? ? ?con=source.getConnection(); ?
// ? ? ?} catch (SQLException e) { ?
// ? ? ? ? ?// TODO Auto-generated catch block ?
// ? ? ? ? ?e.printStackTrace(); ?
// ? ? ?} ?
// ?
// ? ? ?return con; ?
// ?} ?
/**
* 關(guān)閉所有資源
*/
public void closeAll(){
if(rs!=null)
try {
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(ps!=null)
try {
ps.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(con!=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} ?
}
/**
* @param sql數(shù)據(jù)庫更新(增、刪、改) 語句
* @param pras參數(shù)列表(可傳,可不傳,不傳為NULL,以數(shù)組形式存在)
* @return 返回受影響都行數(shù)
*/
public int update(String sql,String... pras){
int resu=0;
con=getCon();
try {
ps=con.prepareStatement(sql);
for(int i=0;ipras.length;i++){
ps.setString(i+1,pras[i]);
}
resu=ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
closeAll();
}
return resu;
}
/**
* @param sql數(shù)據(jù)庫查詢語句
* @param pras參數(shù)列表(可傳,可不傳,不傳為NULL,以數(shù)組形式存在)
* @return 返回結(jié)果集
*/
public ResultSet query(String sql,String... pras){
con=getCon();
try {
ps=con.prepareStatement(sql);
if(pras!=null)
for(int i=0;ipras.length;i++){
ps.setString(i+1, pras[i]);
}
rs=ps.executeQuery();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
} ?
}
package com.cn.jdbc;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
//import java.awt.List;
public class Query {
public ListUserVo showUser(){
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
ListUserVo list=new ArrayListUserVo();
try{
conn=JDBC_Connection.getConnection();
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from users");
while(rs.next()){
UserVo userVo=new UserVo();
userVo.setId(rs.getInt("id"));
userVo.setName(rs.getString("name"));
userVo.setAge(rs.getInt("age"));
userVo.setTel(rs.getString("tel"));
userVo.setAddress(rs.getString("address"));
list.add(userVo);
}
}catch(SQLException e){
e.printStackTrace();
}finally{
JDBC_Connection.free(rs, conn, stmt);
}
return list;
}
public static void main(String[] args) {
Query query=new Query();
ListUserVo list=query.showUser();
if(list!=null){
System.out.print("id\t");
System.out.print("name\t");
System.out.print("age\t");
System.out.print("tel\t");
System.out.print("address\t");
System.out.println();
for(int i=0;ilist.size();i++){
System.out.print(list.get(i).getId()+"\t");
System.out.print(list.get(i).getName()+"\t");
System.out.print(list.get(i).getAge()+"\t");
System.out.print(list.get(i).getTel()+"\t ");
System.out.print(list.get(i).getAddress()+"\t");
System.out.println();
}
}
}
}
要自己加驅(qū)動,,,,這個你應(yīng)該可以看懂吧,,
try{Connection con;
Statement stmt;
ResultSet rs;
int temp;
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/java","root","");//以上是數(shù)據(jù)庫連接,不同的數(shù)據(jù)管理器有 //不同的驅(qū)動和鏈接方式,以上是mysql的連接
stmt=con.createStatement();
rs=stmt.executeQuery("select * from student");//執(zhí)行查詢語句,結(jié)果賦值給結(jié)果集rs
//結(jié)果集是結(jié)果于字段編號的映射,每一個字
//段都有一個編號,最小為1,也就是第一個字段
while(rs.next()){
String names=rs.getString("name");//查詢結(jié)果轉(zhuǎn)換成字符串。
System.out.println(names);
}rs.close();
}catch(Exception e){
e.printStackTrace();
}
網(wǎng)頁題目:java范圍查詢代碼,java實現(xiàn)查詢功能代碼
文章出自:http://chinadenli.net/article8/dsgddop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、虛擬主機(jī)、商城網(wǎng)站、App設(shè)計、建站公司、網(wǎng)頁設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)