Thursday 15 September 2011

java - Connect database with MyBatis without xml file -


I am trying to connect a small Java application with a database using MyBatis.

XML file:

  & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt ;! DOCTYPE PUBLIC CONFIGURATION "- // mybatis.org//DTD Config 3.0 // n" "http://mybatis.org/dtd/mybatis-3-config.dtd"> & Lt; Configuration & gt; & Lt; Environment default = "development" & gt; & Lt; Environmental ID = "Development" & gt; & Lt; Transaction Manager Type = "JDBC" /> & Lt; Data Source Type = "Piled" & gt; & Lt; Property Name = "Driver" value = "oracle.jdbc.driver.OracleDriver" /> & Lt; Property Name = "url" value = "jdbc: oracle: thin: @xxxx: xxxx: xxxx" /> & Lt; Property Name = "User Name" Value = "xxxxx" /> & Lt; Property name = "password" value = "xxxxx" /> & Lt; / Data source & gt; & Lt; / Environment & gt; & Lt; / Environment & gt; & Lt; Cartographers & gt; & Lt; Mapper Resources = "xml / mapper.xml" /> & Lt; / Cartographers & gt; & Lt; / Configuration & gt;   

Earlier, I found the session like this:

  string processing = "configuration .xml"; Sql session session = null; {Reader Reader = Try Resources. Reset resource reader (resource); SqlSessionFactory sqlMapper = New SqlSessionFactoryBuilder () Build (reader); Session = sqlMapper.open session ();   

I want to connect to the database without using the XML file. Any help would be appreciated.

Have you checked the MyBatis 3 user guide? There is no need to use XML based mapping without "XML Building SqlSessionFactory", you can use annotation based statement mapping and can completely avoid XML configuration.

No comments:

Post a Comment