源码:
public class MyConn {
private static SqlMapClient sqlMapper;
static{
try {
Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml") ;
sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader) ;
reader.close() ;
} catch (IOException e) {
System.out.println("连接失败!");
e.printStackTrace() ;
}
}
SqlMapConfig.xml的配置:
<sqlMapConfig>
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property name="JDBC.Driver"
value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<property name="JDBC.ConnectionURL"
value="jdbc:microsoft:sqlserver://localhost:1433;databaseName=db_bookmanage;SelectMethod=Cursor" />
<property name="JDBC.Username" value="lshhb" />
<property name="JDBC.Password" value="lshhb" />
</dataSource>
</transactionManager>
</sqlMapConfig>