java»ñÈ¡SQL²éѯ½á¹û¼¯ÖеÄÐÐÊýºÍÁÐÊý
http://cheneyph.javaeye.com/blog/477829
ÔÚJavaÖУ¬»ñµÃResultSetµÄ×ÜÐÐÊýµÄ·½·¨ÓÐÒÔϼ¸ÖÖ¡£
µÚÒ»ÖÖ£ºÀûÓÃResultSetµÄgetRow·½·¨À´»ñµÃResultSetµÄ×ÜÐÐÊý
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rset = stmt.executeQuery("select * from yourTableName");
rset.last();
int rowCount = rset.getRow(); //»ñµÃResultSetµÄ×ÜÐÐÊý
µÚ¶þÖÖ£ºÀûÓÃÑ»·ResultSetµÄÔªËØÀ´»ñµÃResultSetµÄ×ÜÐÐÊý
ResultSet rset = stmt.executeQuery("select * from yourTableName");
int rowCount = 0;
while(rset.next()) {
rowCount++;
}
rowCount¾ÍÊÇResultSetµÄ×ÜÐÐÊý¡£
µÚÈýÖÖ£ºÀûÓÃsqlÓï¾äÖеÄcountº¯Êý»ñµÃResultSetµÄ×ÜÐÐÊý
ResultSet rset = stmt.executeQuery("select count(*) totalCount from yourTableName");
int rowCount = 0;
if(rset.next()) {
rowCount=rset .getInt("totalCount ");
}
rowCount¾ÍÊÇResultSetµÄ×ÜÐÐÊý¡£
· *****************************************************************************************************************
· JavaÖлñµÃResultSetµÄ×ÜÁÐÊýÊǷdz£¼òµ¥ÊÂÇ飬ÒòΪJavaÖÐResultSetÌṩÁËResultSetMetaData¹¤¾ßÀà,ResultSetMetaData ÊÇResultSetµÄÔªÊý¾ÝµÄ¼¯ºÏ˵Ã÷¡£
java»ñµÃResultSet×ÜÁÐÊýµÄ´úÂëÈçÏ£º
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rset = stmt.executeQuery("select * from yourtable");
ResultSetMetaData rsmd = rset.getMetaData() ;
int columnCount = rsmd.getColumnCount();
columnCount&nb
Ïà¹ØÎĵµ£º
Ëæ×ÅB/SģʽӦÓÿª·¢µÄ·¢Õ¹£¬Ê¹ÓÃÕâÖÖģʽ±àдӦÓóÌÐòµÄ³ÌÐòÔ±Ò²Ô½À´Ô½¶à¡£µ«ÊÇÓÉÓÚÕâ¸öÐÐÒµµÄÈëÃÅÃż÷²»¸ß£¬³ÌÐòÔ±µÄˮƽ¼°¾ÑéÒ²²Î²î²»Æë£¬Ï൱´óÒ»²¿·Ö³ÌÐòÔ±ÔÚ±àд´úÂëµÄʱºò£¬Ã»ÓжÔÓû§ÊäÈëÊý¾ÝµÄºÏ·¨ÐÔ½øÐÐÅжϣ¬Ê¹Ó¦ÓóÌÐò´æÔÚ°²È«Òþ»¼¡£Óû§¿ÉÒÔÌá½»Ò»¶ÎÊý¾Ý¿â²éѯ´úÂ룬¸ù¾Ý³ÌÐò·µ»ØµÄ½á¹û£¬»ñµÃijЩËûÏëµÃÖªµÄÊ ......
SQL²åÈëÓï¾äµÃµ½×Ô¶¯Éú³ÉµÄµÝÔö ID Öµ
insert into Table1(Name,des,num) values ('ltp','thisisbest',10);
select @@identity as 'Id'
Ëæ»úÌáÈ¡Ìõ¼Ç¼µÄÀý×Ó
SQL Server£ºSelect Top 10 * from Tablename Order ......
Transact-SQL ÌṩÁË(BEGIN...END¡¢BREAK¡¢GOTO¡¢CONTINUE¡¢IF...ELSE¡¢WHILE¡¢RETURN¡¢WAITFOR)¿ØÖÆÁ÷¹Ø¼ü×Ö£¬ÓÃÓÚ¿ØÖÆ Transact-SQL Óï¾ä¡¢Óï¾ä¿é¡¢Óû§¶¨Ò庯ÊýÒÔ¼°´æ´¢¹ý³ÌµÄÖ´ÐÐÁ÷¡£ ²»Ê¹ÓÿØÖÆÁ÷ÓïÑÔ£¬Ôò¸÷ Transact-SQL Óï¾ä°´Æä³öÏÖµÄ˳Ðò·Ö±ðÖ´ÐС£¿ØÖÆÁ÷ÓïÑÔʹÓÃÓë³ÌÐòÉè¼ÆÏàËÆµÄ¹¹ÔìʹÓï¾äµÃÒÔ»¥ÏàÁ¬½Ó¡¢¹ØÁªºÍ ......
½»²æ±íÓï¾äµÄʵÏÖ:
¡¡¡¡ÓÃÓÚ:½»²æ±íµÄÁÐÊýÊÇÈ·¶¨µÄ
¡¡¡¡select name,sum(case subject when 'Êýѧ' then source else 0 end) as 'Êýѧ',
¡¡¡¡sum(case subject when 'Ó¢Óï' then source else 0 end) as 'Ó¢Óï',
¡¡¡¡sum(case subject when 'ÓïÎÄ' then source else 0 end) as 'ÓïÎÄ'
¡¡¡¡from test
¡¡¡¡group by name ......