JBoss-mysql learning notes

zhaozj2021-02-16  56

First, develop BMP in JBuilderx

Session Bean ClientHandle, there is no use of not to explain.

BEAN-managed persistence - BMP explains in detail here (DBHANDLE).

1.1 Domain M_ID, M_Name, M_CITY is a one in one by one in the record column in the Member table in the database SAMP_DB.

1.2 m

_CONN is used to save database connections from the connection pool.

1.3 m

_PSTMT is a statement object acquired with m_conn

1.4 getConnection is a customized method from the connection pool.

1.5 Selectall Query all records in the MEMBER table Add to the Vector. This REMOTE method is used by the client.

1.6 EJBStore Save Data into the Database to update records in the database. This function is automatically called by the container!

1.7 EJBLOAD reads data from the database to update the contents of BMP. This function is automatically called by the container!

1.8 EJBFindByPrimaryKey queries in the Member table of the database by the primary key.

First, build a table in MySQL

2.1 Table structure As shown below:

2.1 Make MySQL support Chinese configuration.

Configure the C: /Windows/my.ini file. Add Default-Character-set = GBK to encode the DEFAULT-CHARACTER-SET = GBK under [MySQLD] and [Client] items. If you don't have [Client], create one!

As shown below:

[mysqld]

Default-character-set = GBK

[client]

DEFAULT-character-set = GBK 3, configure jboss

3.1 Download the mysql JDBC driver from www.mysql.org. Copy the drive to: JBoss installation directory f: / jboss3_tomcat4 / lib. As shown in the figure below, I am currently using mysql-connector-java-

3.0.12

-Production.zip The mysql-connector-java-3.0.12-production-bin.jar file in the compression package will copy the driver to: JBoss installation directory f: / jboss3_tomcat4 / lib.

3.2 Copy the files under the JBoss installation directory / DOCS / EXAMPLES / JCA: mysql-service.xml to the JBoss installation directory / server / default / deploy directory.

"This is replaced with braces {,} here," is replaced with braces {,}. "

3.3 JBoss installation directory / Server/default/deploy/mysql-service.xml

{Attribute name = "JndiName"} MySqlDS {/ attribute} {attribute name = "ManagedConnectionFactoryProperties"} {properties} {config-property name = "ConnectionURL" type = "java.lang.String"} jdbc: mysql: // mysql Server IP Address: 3306 / Database Name {/ config-property} {config-proty = "driverclass" type = "java.lang.string"} com.mysql.jdbc.driver {/ config-property} {config- Property name = "username" type = "java.lang.string"} Enter your username {/ config-proteTy} {config-property name = "password" type = "java.lang.string"} Enter your password {/ config-protety} {/ property} {/attribute }3.4 jboss installation directory / Server/default/conf/standardjbosscmp-jdbc.xml

{jbosscmp-jdbc}

{Defaults}

{DataSource} java: / mysqlds {/ datasource}

{DataSource-maping} mysql {/ datasource-maping}

3.5 jboss

Installation directory / Server/default/conf/standardjaws.xml

{jaws}

{DataSource} java: / mysqlds {/ datasource}

{type-mapping} mysql {/ type-maping}

{Debug} false {/ debug}

3.6 JBoss Installation Directory / Server/default/conf/login-config.xml {Application-Policy Name = "mysqldbRealm"}

{Authentication}

{login-module code = "org.jboss.Resource.security.configuredentityLoginmodule" flag = "required"}

{Module-option name = "principal"} root {/ module-option}

{Module-Option Name = "UserName"} Enter your username {/ module-option}

{Module-Option Name = "password"} Enter your password {/ module-option}

{module-option name = "managedConnectionFactoryName"}

JBoss.jca: service = localtxcm, name = mysqlds

{/ module-option}

{/ login-module}

{/ Authentication}

{/ Application-Policy}

3.7

You can use the following code to get the connection in the database connection pool.

InitialContext JCT = New InitialContext ();

DataSource DS = (Datasource) JCT.LOOKUP ("Java: / MySQLDS"); System.out.Println ("Successful Find MySqlds);

Connection conn = ds.getConnection ();

Fourth, the running results in JBUILDERX after starting JBoss and MySQL are shown below: Note: garbled is due to the length of the inserted data exceeds the length defined in the table! As long as you define the record items in the MySQL table to be garbled! ! !

Additional: MySql example construction of the table: @@@@@@@@@@@ built as shown below in Table @@@@@@@@@@@@@

@@@@@@@@@@@@@4

Insert data and query data @@@@@@@@@@@@@@@@@@@

转载请注明原文地址:https://www.9cbs.com/read-18430.html

New Post(0)