ywlcn / SpringStudy

TempSampleSource
0 stars 0 forks source link

SpringJDBC study #9

Open ywlcn opened 5 years ago

ywlcn commented 5 years ago

程序里面定义


- **jdbc.properties**

jdbc.driverClassName=org.gjt.mm.mysql.Driver jdbc.url=jdbc:mysql://127.0.0.1:3306/test_db jdbc.username=root jdbc.password=root

ywlcn commented 5 years ago

Web服务器上定义

<resource-ref>
    <res-ref-name>jdbc/TestDB</res-ref-name>
    <res-type>java.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
ywlcn commented 5 years ago

内嵌式定义

<jdbc:embedded-database type="H2" id="dataSource" />
<jdbc:initialize-database data-source="dataSource">
    <jdbc:script location="classpath:/db/function.sql" />
</jdbc:initialize-database>
ywlcn commented 5 years ago

数据结果变换

RowMapper

ResultSetExtractor

与 RowMapper 的区别是 可以对 RusultSet进行 Next操作, 所以可以一次把所有的数据处理完。 RowMapper 可以取 但是不推荐

RowCallbackHandler

没有返回值 Override void processRow

new RowCallbackHandler() {                      
    @Override   
    public void processRow(ResultSet rs) throws SQLException 
    {               
        Userinfo user= new Userinfo();              
        user.setName(rs.getString("XXXX"));             
        user.setPass(rs.getString("XXXX"));
        user.setId(rs.getInt("XXX"));       
        lists.add(user);            
    }       
}
ywlcn commented 5 years ago

事務處理
傳播Level 事務裏面調用事務

ywlcn commented 5 years ago

Error

DB2* -007,-029,-097,-104,-109,-115,-128,-199,-204,-206,-301,-408,-441,-491 -904,-971 -407,-530,-531,-532,-543,-544,-545,-603,-667,-803 -911,-913 Apache Derby true 42802,42821,42X01,42X02,42X03,42X04,42X05,42X06,42X07,42X08 04501,08004,42Y07 22001,22005,23502,23503,23505,23513,X0Y32 40XL1 40001 42000,42001,42101,42102,42111,42112,42121,42122,42132 90046,90100,90117,90121,90126 22003,22012,22025,23000,23001 HSQL Database Engine -22,-28 -80 -9 Informix Dynamic Server -201,-217,-696 -239,-268,-692,-11030 Microsoft SQL Server 156,170,207,208 229 544,2601,2627,8114,8115 1205 1054,1064,1146 1 630,839,840,893,1062,1169,1215,1216,1217,1451,1452,1557 1205 1213 900,903,904,917,936,942,17006 17003 17002,17447 1,1400,1722,2291,2292 54 8177 60 true 03000,42000,42601,42602,42622,42804,42P01 53000,53100,53200,53300 23000,23502,23503,23505,23514 55P03 40001 40P01 Sybase SQL Server Adaptive Server Enterprise sql server 101,102,103,104,105,106,107,108,109,110,111,112,113,116,120,121,123,207,208,213,257,512 423,511,515,530,547,2601,2615,2714 1205