1. 程式人生 > >mybatis分頁查詢之sql server--mysql

mybatis分頁查詢之sql server--mysql

         在習慣了使用mysql進行資料操作後,突然轉到sql server,雖然說兩者在mybatis中的語法基本相同,很容易替換,但是,這也是最容易出問題的地方,因為往往我們會被這些些微的“不同”坑害。

         今天這裡就分享一下mysql和sql server在分頁查詢中的區別以及這裡的“坑”。

首先看一下mysql中分頁查詢的程式碼:

select * from sys_dormitoryBuilding limit 1,2;
這句sql語句執行的效果是選擇第一行後的兩行作為結果,也就是選擇2、3兩行,從這個例子,我們就可以寫出如下的xml語句了:
<select id="selectByOptions" parameterType="com.huan.common.SearchCondition" resultMap="BuildingResult">
		select * from sys_dormitoryBuilding 
		<where>
		    1=1
			<if test="searchBean.buildingNum != null and searchBean.buildingNum != ''">
				and building_number like CONCAT('%',#{searchBean.buildingNum,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.name != null and searchBean.name != ''">
				and name like CONCAT('%',#{searchBean.name,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.address != null and searchBean.address != ''">
				and address like CONCAT('%',#{searchBean.address,jdbcType=INTEGER},'%')
			</if>
		</where>
		limit #{searchBean.start},#{searchBean.rows};
	</select>

      解釋一下上面的語句,parameterType中的值是一個類,SearchCondition存放的是查詢的引數,where裡面的我們也就不看了,這是根據引數進行資訊篩選的,limit #{searchBean.start},#{searchBean.rows},這句話我們重點看一下,這就是我們mysql裡的分頁查詢方法,可以使用limit進行查詢,#{searchBean.start}代表起始位置,#{searchBean.rows}代表每頁的資料行數。

       看到這裡,一切都是沒問題的。對於limit,可以說是很好用了,但是sql server中並沒有提供limit這樣的操作,所以想要直接進行分頁是不可能的。下面我們來看一下sql server中top使用的一種情況:

select top 2 * from staffInfo
where cardNum not in (
  select top 1 cardNum from staffInfo
)
在上面的sql語句中,就可以實現mysql中同樣的功能了,選取的是2、3行的資料,這個語句很好理解,當然,效率上是有點小小的瑕疵。
<select id="selectByOptions" parameterType="com.huan.common.SearchCondition" resultMap="StaffResult">
		select top #{searchBean.rows} * from staffInfo
		<where>
		    1=1
			<if test="searchBean.cardNum != null and searchBean.cardNum != ''">
				and cardNum like CONCAT('%',#{searchBean.cardNum,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.realname != null and searchBean.realname != ''">
				and realname like CONCAT('%',#{searchBean.realname,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.department != null and searchBean.department != ''">
				and department like CONCAT('%',#{searchBean.department,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.job != null and searchBean.job != ''">
				and job like CONCAT('%',#{searchBean.job,jdbcType=VARCHAR},'%')
			</if>
			<if test="searchBean.available != null and searchBean.available != ''">
				and available like CONCAT('%',#{searchBean.sssssavailable,jdbcType=VARCHAR},'%')
			</if>
			and cardNum not in (
               select top #{searchBean.start} cardNum from staffInfo
             )
		</where>
	</select>
        對於上面的程式碼,我們對照下sql server中的語法,感覺是不是沒毛病?那應該就是可以執行的了。可是,現實是殘酷的,這個程式碼是會報錯的。特別是對於xml封裝的sql語句,我們找錯就更加難了。
錯誤的提示資訊如下(資訊有點多我,我就擷取一部分):

         從上面我們可以看出,對於輸出的sql語句部分,用“?”代替的,我們是看不見的,這就是問題的關鍵(說實話,處於mysql這個用多了,我排除了好多的原因,找到這個真不容易),這個問題就在於我們這裡使用的“#”,這就會導致我們的查詢語句出現了問題,#在mysql中的用法和sql server中確實有了差別,在sql server中,#括起來的變數在使用中會自動新增引號,這就是強制把我們的變數變成了字串了啊,而我們這裡顯然要用的是整數值,這明顯就是錯誤的,所以知道這個錯誤的我內心也是。。。,這裡只需要將“#”替換為“$”就行了。

下面是我從網上搜到的關於“#”和“$”符號的解釋:

1、#是把傳入的資料當作字串,如#field#傳入的是id,則sql語句生成是這樣,order by “id”,這當然會報錯。 
2、$傳入的資料直接生成在sql裡,如#field#傳入的是id,則sql語句生成是這樣,order by id, 這就對了。 
3、#方式能夠很大程度防止sql注入。 
4、$方式無法防止sql注入。 
5、$方式一般用於傳入資料庫物件,例如傳入表名。 
6、一般能用#的就別用$。

        好了,這次就分享這麼多,下面貼上錯誤的完整資訊,以便於別人查詢。

[ssmTest] 2017-10-26 11:51:45 freemarker.beans Key "location" was not found on instance of org.springframework.jdbc.UncategorizedSQLException. Introspection information for the class is: {getClass=public final native java.lang.Class java.lang.Object.getClass(), SQLException=java.beans.PropertyDescriptor[name=SQLException; propertyType=class java.sql.SQLException; readMethod=public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException()], getLocalizedMessage=public java.lang.String java.lang.Throwable.getLocalizedMessage(), cause=java.beans.PropertyDescriptor[name=cause; propertyType=class java.lang.Throwable; readMethod=public synchronized java.lang.Throwable java.lang.Throwable.getCause()], getCause=public synchronized java.lang.Throwable java.lang.Throwable.getCause(), sql=java.beans.PropertyDescriptor[name=sql; propertyType=class java.lang.String; readMethod=public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql()], getSql=public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql(), getStackTrace=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace(), addSuppressed=public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable), hashCode=public native int java.lang.Object.hashCode(), rootCause=java.beans.PropertyDescriptor[name=rootCause; propertyType=class java.lang.Throwable; readMethod=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause()], getSuppressed=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed(), suppressed=java.beans.PropertyDescriptor[name=suppressed; propertyType=class [Ljava.lang.Throwable;; readMethod=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()], stackTrace=java.beans.PropertyDescriptor[name=stackTrace; propertyType=class [Ljava.lang.StackTraceElement;; readMethod=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()], getRootCause=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause(), class=java.beans.PropertyDescriptor[name=class; propertyType=class java.lang.Class; readMethod=public final native java.lang.Class java.lang.Object.getClass()], localizedMessage=java.beans.PropertyDescriptor[name=localizedMessage; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getLocalizedMessage()], [email protected], initCause=public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable), mostSpecificCause=java.beans.PropertyDescriptor[name=mostSpecificCause; propertyType=class java.lang.Throwable; readMethod=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause()], getMessage=public java.lang.String org.springframework.core.NestedRuntimeException.getMessage(), message=java.beans.PropertyDescriptor[name=message; propertyType=class java.lang.String; readMethod=public java.lang.String org.springframework.core.NestedRuntimeException.getMessage()], getMostSpecificCause=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause(), [email protected][email protected], contains=public boolean org.springframework.core.NestedRuntimeException.contains(java.lang.Class), setStackTrace=public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]), [email protected]={public java.lang.String java.lang.Throwable.getLocalizedMessage()=[Ljava.lang.Class;@72f2cc03, public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)=[Ljava.lang.Class;@608ea13e, public java.lang.String org.springframework.core.NestedRuntimeException.getMessage()=[Ljava.lang.Class;@73eda0c8, public native int java.lang.Object.hashCode()=[Ljava.lang.Class;@64318af1, public boolean java.lang.Object.equals(java.lang.Object)=[Ljava.lang.Class;@c7d0a0, public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause()=[Ljava.lang.Class;@15d516d7, public synchronized java.lang.Throwable java.lang.Throwable.getCause()=[Ljava.lang.Class;@ba01f45, public boolean org.springframework.core.NestedRuntimeException.contains(java.lang.Class)=[Ljava.lang.Class;@63ae6ac2, public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException()=[Ljava.lang.Class;@5d52e4c7, public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])=[Ljava.lang.Class;@608c2214, public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()=[Ljava.lang.Class;@6b5d5377, public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)=[Ljava.lang.Class;@7b35dca4, public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql()=[Ljava.lang.Class;@318b6bd9, public java.lang.String java.lang.Throwable.toString()=[Ljava.lang.Class;@3096737e, public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()=[Ljava.lang.Class;@31d148f0, public final native java.lang.Class java.lang.Object.getClass()=[Ljava.lang.Class;@64546292, public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause()=[Ljava.lang.Class;@eeb1862, public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()=[Ljava.lang.Class;@de59742}, equals=public boolean java.lang.Object.equals(java.lang.Object), toString=public java.lang.String java.lang.Throwable.toString(), getSQLException=public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException(), fillInStackTrace=public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()}
[ssmTest] 2017-10-26 11:51:45 freemarker.beans Key "location" was not found on instance of org.springframework.jdbc.UncategorizedSQLException. Introspection information for the class is: {getClass=public final native java.lang.Class java.lang.Object.getClass(), SQLException=java.beans.PropertyDescriptor[name=SQLException; propertyType=class java.sql.SQLException; readMethod=public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException()], getLocalizedMessage=public java.lang.String java.lang.Throwable.getLocalizedMessage(), cause=java.beans.PropertyDescriptor[name=cause; propertyType=class java.lang.Throwable; readMethod=public synchronized java.lang.Throwable java.lang.Throwable.getCause()], getCause=public synchronized java.lang.Throwable java.lang.Throwable.getCause(), sql=java.beans.PropertyDescriptor[name=sql; propertyType=class java.lang.String; readMethod=public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql()], getSql=public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql(), getStackTrace=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace(), addSuppressed=public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable), hashCode=public native int java.lang.Object.hashCode(), rootCause=java.beans.PropertyDescriptor[name=rootCause; propertyType=class java.lang.Throwable; readMethod=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause()], getSuppressed=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed(), suppressed=java.beans.PropertyDescriptor[name=suppressed; propertyType=class [Ljava.lang.Throwable;; readMethod=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()], stackTrace=java.beans.PropertyDescriptor[name=stackTrace; propertyType=class [Ljava.lang.StackTraceElement;; readMethod=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()], getRootCause=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause(), class=java.beans.PropertyDescriptor[name=class; propertyType=class java.lang.Class; readMethod=public final native java.lang.Class java.lang.Object.getClass()], localizedMessage=java.beans.PropertyDescriptor[name=localizedMessage; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getLocalizedMessage()], [email protected], initCause=public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable), mostSpecificCause=java.beans.PropertyDescriptor[name=mostSpecificCause; propertyType=class java.lang.Throwable; readMethod=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause()], getMessage=public java.lang.String org.springframework.core.NestedRuntimeException.getMessage(), message=java.beans.PropertyDescriptor[name=message; propertyType=class java.lang.String; readMethod=public java.lang.String org.springframework.core.NestedRuntimeException.getMessage()], getMostSpecificCause=public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause(), [email protected][email protected], contains=public boolean org.springframework.core.NestedRuntimeException.contains(java.lang.Class), setStackTrace=public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]), [email protected]={public java.lang.String java.lang.Throwable.getLocalizedMessage()=[Ljava.lang.Class;@72f2cc03, public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)=[Ljava.lang.Class;@608ea13e, public java.lang.String org.springframework.core.NestedRuntimeException.getMessage()=[Ljava.lang.Class;@73eda0c8, public native int java.lang.Object.hashCode()=[Ljava.lang.Class;@64318af1, public boolean java.lang.Object.equals(java.lang.Object)=[Ljava.lang.Class;@c7d0a0, public java.lang.Throwable org.springframework.core.NestedRuntimeException.getMostSpecificCause()=[Ljava.lang.Class;@15d516d7, public synchronized java.lang.Throwable java.lang.Throwable.getCause()=[Ljava.lang.Class;@ba01f45, public boolean org.springframework.core.NestedRuntimeException.contains(java.lang.Class)=[Ljava.lang.Class;@63ae6ac2, public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException()=[Ljava.lang.Class;@5d52e4c7, public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])=[Ljava.lang.Class;@608c2214, public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()=[Ljava.lang.Class;@6b5d5377, public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)=[Ljava.lang.Class;@7b35dca4, public java.lang.String org.springframework.jdbc.UncategorizedSQLException.getSql()=[Ljava.lang.Class;@318b6bd9, public java.lang.String java.lang.Throwable.toString()=[Ljava.lang.Class;@3096737e, public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()=[Ljava.lang.Class;@31d148f0, public final native java.lang.Class java.lang.Object.getClass()=[Ljava.lang.Class;@64546292, public java.lang.Throwable org.springframework.core.NestedRuntimeException.getRootCause()=[Ljava.lang.Class;@eeb1862, public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()=[Ljava.lang.Class;@de59742}, equals=public boolean java.lang.Object.equals(java.lang.Object), toString=public java.lang.String java.lang.Throwable.toString(), getSQLException=public java.sql.SQLException org.springframework.jdbc.UncategorizedSQLException.getSQLException(), fillInStackTrace=public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()}
[ssmTest] 2017-10-26 11:51:45 freemarker.beans Key "location" was not found on instance of com.microsoft.sqlserver.jdbc.SQLServerException. Introspection information for the class is: {getClass=public final native java.lang.Class java.lang.Object.getClass(), getLocalizedMessage=public java.lang.String java.lang.Throwable.getLocalizedMessage(), errorCode=java.beans.PropertyDescriptor[name=errorCode; propertyType=int; readMethod=public int java.sql.SQLException.getErrorCode()], cause=java.beans.PropertyDescriptor[name=cause; propertyType=class java.lang.Throwable; readMethod=public synchronized java.lang.Throwable java.lang.Throwable.getCause()], getSQLState=public java.lang.String java.sql.SQLException.getSQLState(), setNextException=public void java.sql.SQLException.setNextException(java.sql.SQLException), getCause=public synchronized java.lang.Throwable java.lang.Throwable.getCause(), SQLState=java.beans.PropertyDescriptor[name=SQLState; propertyType=class java.lang.String; readMethod=public java.lang.String java.sql.SQLException.getSQLState()], iterator=public java.util.Iterator java.sql.SQLException.iterator(), getStackTrace=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace(), addSuppressed=public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable), getErrorCode=public int java.sql.SQLException.getErrorCode(), hashCode=public native int java.lang.Object.hashCode(), getNextException=public java.sql.SQLException java.sql.SQLException.getNextException(), getSuppressed=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed(), suppressed=java.beans.PropertyDescriptor[name=suppressed; propertyType=class [Ljava.lang.Throwable;; readMethod=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()], stackTrace=java.beans.PropertyDescriptor[name=stackTrace; propertyType=class [Ljava.lang.StackTraceElement;; readMethod=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()], class=java.beans.PropertyDescriptor[name=class; propertyType=class java.lang.Class; readMethod=public final native java.lang.Class java.lang.Object.getClass()], localizedMessage=java.beans.PropertyDescriptor[name=localizedMessage; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getLocalizedMessage()], [email protected], initCause=public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable), getMessage=public java.lang.String java.lang.Throwable.getMessage(), message=java.beans.PropertyDescriptor[name=message; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getMessage()], setStackTrace=public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]), [email protected]={public java.util.Iterator java.sql.SQLException.iterator()=[Ljava.lang.Class;@7c174ec5, public java.lang.String java.lang.Throwable.getLocalizedMessage()=[Ljava.lang.Class;@519ad3d9, public int java.sql.SQLException.getErrorCode()=[Ljava.lang.Class;@2b5f0093, public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)=[Ljava.lang.Class;@5250dbb8, public java.lang.String java.lang.Throwable.getMessage()=[Ljava.lang.Class;@1477d651, public java.sql.SQLException java.sql.SQLException.getNextException()=[Ljava.lang.Class;@13f4cb1d, public native int java.lang.Object.hashCode()=[Ljava.lang.Class;@407c1a68, public boolean java.lang.Object.equals(java.lang.Object)=[Ljava.lang.Class;@142584c4, public synchronized java.lang.Throwable java.lang.Throwable.getCause()=[Ljava.lang.Class;@3e4a0d4f, public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])=[Ljava.lang.Class;@bd385b8, public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()=[Ljava.lang.Class;@2bdc71f0, public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)=[Ljava.lang.Class;@1367c3eb, public java.lang.String java.sql.SQLException.getSQLState()=[Ljava.lang.Class;@7d2994bd, public java.lang.String java.lang.Throwable.toString()=[Ljava.lang.Class;@6a4020e5, public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()=[Ljava.lang.Class;@225b9fac, public final native java.lang.Class java.lang.Object.getClass()=[Ljava.lang.Class;@f0e6897, public void java.sql.SQLException.setNextException(java.sql.SQLException)=[Ljava.lang.Class;@3eb389b7, public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()=[Ljava.lang.Class;@551fd18c}, equals=public boolean java.lang.Object.equals(java.lang.Object), toString=public java.lang.String java.lang.Throwable.toString(), nextException=java.beans.PropertyDescriptor[name=nextException; propertyType=class java.sql.SQLException; readMethod=public java.sql.SQLException java.sql.SQLException.getNextException()], fillInStackTrace=public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()}
[ssmTest] 2017-10-26 11:51:45 freemarker.beans Key "location" was not found on instance of com.microsoft.sqlserver.jdbc.SQLServerException. Introspection information for the class is: {getClass=public final native java.lang.Class java.lang.Object.getClass(), getLocalizedMessage=public java.lang.String java.lang.Throwable.getLocalizedMessage(), errorCode=java.beans.PropertyDescriptor[name=errorCode; propertyType=int; readMethod=public int java.sql.SQLException.getErrorCode()], cause=java.beans.PropertyDescriptor[name=cause; propertyType=class java.lang.Throwable; readMethod=public synchronized java.lang.Throwable java.lang.Throwable.getCause()], getSQLState=public java.lang.String java.sql.SQLException.getSQLState(), setNextException=public void java.sql.SQLException.setNextException(java.sql.SQLException), getCause=public synchronized java.lang.Throwable java.lang.Throwable.getCause(), SQLState=java.beans.PropertyDescriptor[name=SQLState; propertyType=class java.lang.String; readMethod=public java.lang.String java.sql.SQLException.getSQLState()], iterator=public java.util.Iterator java.sql.SQLException.iterator(), getStackTrace=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace(), addSuppressed=public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable), getErrorCode=public int java.sql.SQLException.getErrorCode(), hashCode=public native int java.lang.Object.hashCode(), getNextException=public java.sql.SQLException java.sql.SQLException.getNextException(), getSuppressed=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed(), suppressed=java.beans.PropertyDescriptor[name=suppressed; propertyType=class [Ljava.lang.Throwable;; readMethod=public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()], stackTrace=java.beans.PropertyDescriptor[name=stackTrace; propertyType=class [Ljava.lang.StackTraceElement;; readMethod=public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()], class=java.beans.PropertyDescriptor[name=class; propertyType=class java.lang.Class; readMethod=public final native java.lang.Class java.lang.Object.getClass()], localizedMessage=java.beans.PropertyDescriptor[name=localizedMessage; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getLocalizedMessage()], [email protected], initCause=public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable), getMessage=public java.lang.String java.lang.Throwable.getMessage(), message=java.beans.PropertyDescriptor[name=message; propertyType=class java.lang.String; readMethod=public java.lang.String java.lang.Throwable.getMessage()], setStackTrace=public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]), [email protected]={public java.util.Iterator java.sql.SQLException.iterator()=[Ljava.lang.Class;@7c174ec5, public java.lang.String java.lang.Throwable.getLocalizedMessage()=[Ljava.lang.Class;@519ad3d9, public int java.sql.SQLException.getErrorCode()=[Ljava.lang.Class;@2b5f0093, public synchronized java.lang.Throwable java.lang.Throwable.initCause(java.lang.Throwable)=[Ljava.lang.Class;@5250dbb8, public java.lang.String java.lang.Throwable.getMessage()=[Ljava.lang.Class;@1477d651, public java.sql.SQLException java.sql.SQLException.getNextException()=[Ljava.lang.Class;@13f4cb1d, public native int java.lang.Object.hashCode()=[Ljava.lang.Class;@407c1a68, public boolean java.lang.Object.equals(java.lang.Object)=[Ljava.lang.Class;@142584c4, public synchronized java.lang.Throwable java.lang.Throwable.getCause()=[Ljava.lang.Class;@3e4a0d4f, public void java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])=[Ljava.lang.Class;@bd385b8, public java.lang.StackTraceElement[] java.lang.Throwable.getStackTrace()=[Ljava.lang.Class;@2bdc71f0, public final synchronized void java.lang.Throwable.addSuppressed(java.lang.Throwable)=[Ljava.lang.Class;@1367c3eb, public java.lang.String java.sql.SQLException.getSQLState()=[Ljava.lang.Class;@7d2994bd, public java.lang.String java.lang.Throwable.toString()=[Ljava.lang.Class;@6a4020e5, public final synchronized java.lang.Throwable[] java.lang.Throwable.getSuppressed()=[Ljava.lang.Class;@225b9fac, public final native java.lang.Class java.lang.Object.getClass()=[Ljava.lang.Class;@f0e6897, public void java.sql.SQLException.setNextException(java.sql.SQLException)=[Ljava.lang.Class;@3eb389b7, public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()=[Ljava.lang.Class;@551fd18c}, equals=public boolean java.lang.Object.equals(java.lang.Object), toString=public java.lang.String java.lang.Throwable.toString(), nextException=java.beans.PropertyDescriptor[name=nextException; propertyType=class java.sql.SQLException; readMethod=public java.sql.SQLException java.sql.SQLException.getNextException()], fillInStackTrace=public synchronized java.lang.Throwable java.lang.Throwable.fillInStackTrace()}

相關推薦

mybatis查詢sql server--mysql

         在習慣了使用mysql進行資料操作後,突然轉到sql server,雖然說兩者在mybatis中的語法基本相同,很容易替換,但是,這也是最容易出問題的地方,因為往往我們會被這些些微的“不同”坑害。          今天這裡就分享一下mysql和sql s

Mybatis查詢pagehelper

引入pom依賴 <!--mybatis分頁查詢外掛--> <dependency> <groupId>com.github.pagehelper</groupId>

MySql實現查詢SQLmysql實現查詢sql語句

refs: http://blog.csdn.net/sxdtzhaoxinguo/article/details/51481430 摘要: MySQL資料庫實現分頁查詢的SQL語句寫法! 一:分頁需求: 客戶端通過傳遞start(頁碼),limit(每頁顯示的條數

oracle 查詢sql server 查詢sql語句

oracle: SELECT * FROM ( SELECT TEMP.* ,ROWNUM RN FROM ( 表) TEMP WHERE ROWNUM <=currentPage * perPageRows ) WHERE RN >  (currentPage

MySql實現查詢SQL

摘要:MySql資料庫實現分頁查詢的SQL語句寫法! 一:分頁需求: 客戶端通過傳遞start(頁碼),limit(每頁顯示的條數)兩個引數去分頁查詢資料庫表中的資料,那我們知道MySql資料庫提供了分頁的函式limit m,n,但是該函式的用法和我們的需求

mybatis查詢,SqlServer 2008 查詢速度很慢

com ima alt 分頁查詢 img bubuko .com nbsp ati 一個業務場景,需要進行union查詢: 查詢速度非常慢,大概要37秒: 直接復制sql在數據庫客戶端執行,速度很快,由此可知是mybatis的原因,在網上搜索,可以配置fetc

mybatis-查詢學習筆記

mybatis-分頁查詢學習筆記 import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.ibatis.session.SqlSession; import cn.itcast

mybatis查詢需要注意的問題

一般對mybatis的分頁查詢的關鍵程式碼就兩行: #currentPage代表當前頁,pageSize代表每頁的行數 PageHelper.startPage(currentPage, pageSize); #查詢的語句 mapper.select(); 一般程式碼在走到mapper.sel

查詢SQL&LINQ)

 1、利用SQL進行分頁查詢  SQL SEVER分頁查詢方式有如下幾種:TOP NOT IN、Max、ROW_NUMBER或者寫儲存過程。其中利用ROW_NUMBER() OVER()分頁處理,相對效率較高。ROW_NUMBER() OVER()函式的基本用法:對查詢

MySQL大資料量查詢方法及其優化 MySQL大資料量查詢方法及其優化

MySQL大資料量分頁查詢方法及其優化   ---方法1: 直接使用資料庫提供的SQL語句---語句樣式: MySQL中,可用如下方法: SELECT * FROM 表名稱 LIMIT M,N ---適應場景: 適用於資料量較少的情況(元組百/千級) --

Oracle 查詢語句SQL

通用模板 SELECT * FROM (SELECT TMP_PAGE.*, ROWNUM ROW_ID FROM ( ...//替換這裡 ) TMP_PAGE WHERE ROWNUM <

解決MongoDB查詢count查詢慢的問題

一、概述 問題描述:在專案中優化動態查詢分頁介面時,發現count查詢很慢(資料量大概30萬),那如何解決這個問題呢? 解決方法:新增索引,多個查詢條件可以新增複合索引 二、測試對比 1. 未加索引時 count所用時間:1810ms   介面總用時:2298ms 2. 新增索引後 新增索引程式碼: d

資料庫面試:查詢SQL寫法

    分頁是很多網站應用或管理系統比較常見的需要實現的需求,是相關開發同學常碰到的需要寫的查詢。開發面試中會不會被問到用SQL寫分頁,因為個人不是開發,就不得而知了。在之前自己參加的資料庫崗位的面試中,被問到用SQL寫分頁,所以這裡記錄一下。 SELECT t.`colu

mybatis 查詢

  <!-- 分頁查詢 -->   <select id="datalistPage" parameterType="page" resultType="pd" useCache="false">     select *

SpringBoot + mybatis 查詢

com.github.pagehelper.PageHelper是一款好用的開源免費的Mybatis第三方分頁外掛。使用的時候,只要簡單配置,就可以在查詢語句之後得到所需的分頁資訊。 1:在 pom.

mysql sql查詢語句

mysql select body from 記錄 condition rom col mysq SELECT * FROM ‘table‘ ORDER BY ‘condition‘ DESC LIMIT ‘開始索引‘,‘記錄數‘ mysql sql分頁查詢語句

MySQL(十)DQL查詢

-c lar jpg not 列表 img IE class HERE 一、應用場景 當要查詢的條目數太多,一頁顯示不全 二、語法 select 查詢列表 from 表 limit 【offset,】size; 2.1、註意: ffset代表的是起始的條目索引,默認從0卡死

mysql 查詢

alt mysq style 我只 rom font 分頁 插入 com 分頁查詢(limit 起始行,查詢幾行) 如果 我只想插入 第一第二行的數據 該怎麽做那 select from student limit 0,2; 分頁查詢當前頁數的數據 select *

SQL Server 資料查詢

最近學習了一下SQL的分頁查詢,總結了以下幾種方法。 首先建立了一個表,隨意插入的一些測試資料,表結構和資料如下圖: 現在假設我們要做的是每頁5條資料,而現在我們要取第三頁的資料。(資料太少,就每頁5條了) 方法一: select top 5 * from [Stu

Mybatis-plusRowBounds實現查詢

物理分頁和邏輯分頁 物理分頁:直接從資料庫中拿出我們需要的資料,例如在Mysql中使用limit。 邏輯分頁:從資料庫中拿出所有符合要求的資料,然後再從這些資料中拿到我們需要的分頁資料。 優缺點 物理分頁每次都要訪問資料庫,邏輯分頁只訪問一次。 物理分頁佔用記憶體少,邏輯分頁相對較多。 物理分頁資