ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Java±ÊÊÔÌâÕûºÏ 24Ò³wordÎĵµÌù³öÀ´(Îå)
2014-11-24 02:23:03 ¡¾´ó ÖРС¡¿ ä¯ÀÀ:3784´Î
Tags£ºJava ÊÔÌâ ÕûºÏ word Îĵµ ³öÀ´
eResultSet(rs);


ConnectionUtils.closeStatement(pStmt);


ConnectionUtils.closeConnection(conn);


}


return flights;


}


public static void main(String[] args) throws Exception {


List ff = new FlightDaoImplForMySQL().


listPagesNewsDB(2, 3,


ConnectionUtils.openConnection());


for(Flight f:ff){


System.out.println(¡°==¡±+f.getId()+¡±=¡±+f.getNum()+¡±==¡±);


}


}


}


¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª¡ª-


//Oracle ÖеķÖÒ³²éѯ ʵÏÖ


import java.io.FileInputStream;


import java.io.InputStream;


import java.sql.Connection;


import java.sql.PreparedStatement;


import java.sql.ResultSet;


import java.sql.SQLException;


import java.text.SimpleDateFormat;


import java.util.ArrayList;


import java.util.List;


import org.dom4j.Document;


import org.dom4j.Element;


import org.dom4j.io.SAXReader;


import week07.domain.News;


import week07.util.ConnectionUtils;


public class NewsDaoImpl implements INewsDao {


/**


* ·ÖÒ³²éѯnews±íµÄËùÓÐÁеÄÊý¾Ý


*


* @param page


* µÚ¼¸Ò³


* @param rowsPerPages


* ÿҳÏÔʾÐÐÊý


* @param con


* Êý¾Ý¿âÁ¬½Ó


* @return ²éѯµ½µÄÊý¾ÝÒÔNews¶ÔÏóµÄÐÎʽ´æ´¢µ½ListÖзµ»Ø


* @throws Exception


* select news_id, title, content, author, pubDate, rn from(


* select news_id, title, content, author, pubDate, rownum rn


* from news


* where rownum < )


* where rn >= ;


*/


public List listPagesNewsDB(int page, int rowsPerPage,


Connection con) throws Exception {


int from = (page ¨C 1) * rowsPerPage + 1;


int to = from + rowsPerPage;


String sql = ¡°select news_id, title, ¡±


+ ¡°content, author, pubDate, rn ¡± + ¡°from ¡±


+ ¡°(select news_id, title, content, ¡±


+ ¡°author, pubDate, rownum rn ¡±


+ ¡°from news where rownum < ) ¡± + ¡°where rn >= ¡±;


Connection conn = null;


PreparedStatement pStmt = null;


ResultSet rs = null;


News news = null;


List newses = new ArrayList();


try {


conn = ConnectionUtils.openConnection();


pStmt = conn.prepareStatement(sql);


pStmt.setInt(1, to);


pStmt.setInt(2, from);


rs = pStmt.executeQuery();


while (rs.next()) {


news = new News();


news.setNewsId(rs.getLong(1));


news.setTitle(rs.getString(2));


news.setContent(rs.getString(3));


news.setAuthor(rs.getString(4));


news.setPubdate(rs.getDate(5));


newses.add(news);


}


} catch (SQLException e) {


e.printStackTrace();


} finally {


ConnectionUtils.closeResultSet(rs);


ConnectionUtils.closeStatement(pStmt);


ConnectionUtils.closeConnection(conn);


}


return newses;


}


}


17¡¢JDBC£¬Hibernate ·ÖÒ³ÔõÑùʵÏÖ£¿


´ð£º·½·¨·Ö±ðΪ£º


1) Hibernate µÄ·ÖÒ³£º


Query query = session.createQuery(¡°from Student¡±);


query.setFirstResult(firstResult);//ÉèÖÃÿҳ¿ªÊ¼µÄ¼Ç¼ºÅ


query.setMaxResults(resultNumber);//ÉèÖÃÿҳÏÔʾµÄ¼Ç¼Êý


Collection students = query.list();


2) JDBC µÄ·ÖÒ³£º¸ù¾Ý²»Í¬µÄÊý¾Ý¿â²ÉÓò»Í¬µÄsql ·ÖÒ³Óï¾ä


ÀýÈç: Oracle ÖеÄsql Óï¾äΪ: ¡°SELECT * FROM (SELECT a.*, rownum r FROM


TB_STUDENT) WHERE r between 2 and 10¡å ²éѯ´Ó¼Ç¼ºÅ2 µ½¼Ç¼ºÅ10 Ö®¼äµÄËùÓмǼ


µ¹Èý½Ç


public class daosanjiao {



public static void main(String[] args) {



for(int i=0;i<4;i++)


{


for(int k=0;k

{


System.out.print(¡± ¡°);


}


for(int j=0;j<7-2*i;j++)


{


System.out.print(¡°*¡±);


}


System.out.println();


}



}


}


42¡¢ÓÃÄãÊìϤµÄÓïÑÔдһ¸öÁ¬½ÓORACLEÊý¾Ý¿âµÄ³ÌÐò,Äܹ»Íê³ÉÐ޸ĺͲéѯ¹¤×÷¡£ ´ð£ºJDBCʾÀý³ÌÐò


ÈçÏ£º public void testJdbc(){


Connection con = null;


PreparedStatement ps = null;


ResultSet rs = null;


try{


//step1£º×¢²áÇý¶¯£»


Class.forName(¡°oracle.jdbc.driver.OracleDriver¡±);


//step 2£º»ñÈ¡Êý¾Ý¿âÁ¬½Ó£»


con=DriverManager.getConnection(


¡°jdbc:oracle:thin:@192.168.0.23:1521:tarena¡±, ¡°openlab¡±,¡±open123¡å);


/************************²é ѯ************************/


//step 3£º´´½¨Statement£»


String sql = ¡°SELECT id, fname, lna

Ê×Ò³ ÉÏÒ»Ò³ 2 3 4 5 6 7 8 ÏÂÒ»Ò³ βҳ 5/9/9
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
ÉÏһƪ£ºÊ²Ã´ÊÇÔ¤±àÒë ºÎʱÐèÒªÔ¤±àÒ룿 ÏÂһƪ£ºOracleÊý¾Ý¿âÃæÊÔÌâ»ã×Ü

×îÐÂÎÄÕÂ

ÈÈÃÅÎÄÕÂ

Hot ÎÄÕÂ

Python

C ÓïÑÔ

C++»ù´¡

´óÊý¾Ý»ù´¡

linux±à³Ì»ù´¡

C/C++ÃæÊÔÌâÄ¿