WebLogic uses the Java Control of dB to access the database

Source: Internet
Author: User

WebLogic uses the Java Control of dB to access the database

Papayas 2006-6-8

I. Methods

For WebLogic pages and data communication, Java controls are generally used to directly access the data connection pool. direct data operations are defined in
In the Java Control, the page stream is used as the logical processing unit of data, and the common page is used as the display layer. We can see that the Weblogic method is
Typical three-tier structure, data layer (Java Control), business logic layer (page stream), display layer (page)

2. Create a connection pool and Data Source

Configure the config. xml file. Here we use the E:/BEA/weblogic81/samples/domains/workshop that comes with weblogic.
Cgserver.

<Jdbcconnectionpool drivername = "oracle. JDBC. Driver. oracledriver"
Logindelayseconds = "1" maxcapacity = "20" name = "Liwei"
Passwordencrypted = "{3DES} wbnjpyuoave =" properties = "user = Liwei"
Targets = "cgserver" url = "JDBC: oracle: thin: @ localhost: 1521: wincn"/>
<Jdbctxdatasource jndiname = "Liwei" name = "Liwei" poolname = "Liwei" targets = "cgserver"/>

Alternatively, you can use the tool> WebLogic Server> data source viewer> to create a data source. You can enter the following parameters:
Drivername = "oracle. JDBC. Driver. oracledriver"
Url = "JDBC: oracle: thin: @ localhost: 1521: wincn"
Then, use the user name and password.

For more information, see the document "connecting to a database using JSP in WebLogic ".

3. Related Pages

Test/testweb/recordset/recordsetcontroller. jpf
Test/testweb/recordset/index. jsp
Test/testweb/recordset/test. jcx Java Control

Iv. Database

Create Table Test (
A varchar2 (10 ),
B varchar2 (10 ),
C varchar2 (10 ),
D varchar2 (10)
)

V. data layer (Java Control)

This example uses the tbltest custom static class to return the dataset. (You can also use netui: gird + recordset for implementation. See the built-in example)
The update method is similar to the insert method, so no specific implementation code is provided.
The data layer does not have any complexity. It only provides sufficient data operation interfaces for the logic layer (page stream. Static class customized by tbltest
It is an essential part for data transmission.
 
Test/testweb/recordset/test. jcx full code
 
Package recordset;

Import com. Bea. Control .*;
Import java. SQL. sqlexception;

/*
* @ JC: connection data-source-JNDI-name = "Liwei"
*/
Public Interface Test extends databasecontrol, Com. Bea. Control. controlextension
{
/**
* @ JC: SQL statement ::
* Insert into test (A, B, C, D)
* Values ({_ A}, {_ B}, {_ c}, {_ d })
*::
*/
Public int insert (string _ A, string _ B, string _ c, string _ D );

/**
* @ JC: SQL statement ::
* Update Test Set B = {_ B}, c = {_ c}, D = {_ d} Where a = {_}
*::
*/
Public int Update (string _ A, string _ B, string _ c, string _ D );

/**
* @ JC: SQL statement ::
* Delete test where a = {_}
*::
*/
Public int Delete (string _ );


/**
* @ JC: SQL statement ::
* Select * from test where a = {_}
*::
*/
Public tbltest select (string _ );

/**
* @ JC: SQL statement ::
* Select * from test
*::
*/
Public tbltest [] selectall ();

Public static class tbltest implements java. Io. serializable
{
Public String;
Public String B;
Public String C;
Public String D;
}
}

6. logic layer (page Stream)

The main code of test/testweb/recordset/recordsetcontroller. jpf is omitted.

Public class recordsetcontroller extends pageflowcontroller
{
/*
*
* @ Common: Control
*/
Private test rectest; // defines the data interface
Private test. tbltest [] recnew; // defines a dataset

// Because the example is connected to an English database, garbled characters may occur. The following is a transcoding function, which is sufficient.
// Describes the key of the logic layer in data processing.
Private string getgbstring (string strin)
{
Try
{
Byte [] tmpbyte = strin. getbytes ("ISO8859-1 ");
Return new string (tmpbyte, "gb2312 ");
}
Catch (exception E)
{
Return "";
}
}

// Return the full record. Call the selectall interface function of rectest.
Public test. tbltest [] getall ()
{
Recnew = rectest. selectall ();
Int I;
For (I = 0; I <recnew. length; I ++)
{
Recnew [I]. A = getgbstring (recnew [I]. );
Recnew [I]. B = getgbstring (recnew [I]. B );
Recnew [I]. c = getgbstring (recnew [I]. C );
Recnew [I]. d = getgbstring (recnew [I]. D );
}
Return recnew;
}



// Add data. In this case, call the interface to add data through the parameter value passed on the page.
/**
* @ Jpf: Action
* @ Jpf: Forward name = "success" Path = "index. jsp"
*/
Public forward add ()
{
Rectest. insert (this. getrequest (). getparameter ("A"), this. getrequest (). getparameter ("B"), this. getrequest (). getparameter ("C"), this. getrequest (). getparameter ("D "));
Return new forward ("success ");
}

// Delete data
/**
* @ Jpf: Action
* @ Jpf: Forward name = "success" Path = "index. jsp"
*/
Public forward delete ()
{
Rectest. Delete (this. getrequest (). getparameter ("todelete "));
Return new forward ("success ");
}

/**
* This method indicates the entrance to the page stream.
* @ Jpf: Action
* @ Jpf: Forward name = "success" Path = "index. jsp"
*/
Protected forward begin ()
{
Return new forward ("success ");
}
}

7. Display layer (page)

Test/testweb/recordset/index. jsp display at the outermost layer. When you view the complete code below, you can see that the netui control is extremely large.
Flexibility.
 
There are not many technical difficulties. Here, netui-data: repeater is used to obtain record set data repeatedly.
 
<Body>
<Table border = 1>
<Tr>
<TD width = "100" class = "header-text"> A </TD>
<TD width = "100" class = "header-text"> B </TD>
<TD width = "100" class = "header-text"> C </TD>
<TD width = "100" class = "header-text"> d </TD>
</Tr>
<Netui-data: repeater datasource = "{pageflow. All}">
<Netui-data: repeaterheader> </netui-data: repeaterheader>
<Netui-data: repeateritem>
<Tr>
<TD width = "100" class = "Row-text"> <a href = "#" onclick = "window. alert ('<netui: content value =' {container. item. a}-{container. item. b}-{container. item. c}-{container. item. d} '/>') "> <netui: Label value =" {container. item. a} "/> </a> </TD>
<TD width = "100" class = "Row-text"> <netui: Label value = "{container. item. B}"/> </TD>
<TD width = "100" class = "Row-text"> <netui: Label value = "{container. item. c}"/> </TD>
<TD width = "100" class = "Row-text"> <netui: Label value = "{container. item. d}"/> </TD>
<TD>
<Netui: Anchor action = "delete" onclick = "Return (window. Confirm ('del? ') ">
<Netui: parameter name = "todelete" value = "{container. item. A}"/>
Delete
</Netui: Anchor>
</TD>
</Tr>
</Netui-data: repeateritem>
<Netui-data: repeaterfooter> </netui-data: repeaterfooter>
</Netui-data: repeater>
</Table>
<HR>
<Netui: Form Action = "add">
A: <input type = "text" name = "A"/> <br>
B: <input type = "text" name = "B"/> <br>
C: <input type = "text" name = "C"/> <br>
D: <input type = "text" name = "D"/> <br>
<Input type = "Submit" value = "add">
</Netui: Form>
</Body>

VIII. Summary

The previous knowledge of Java is 0, because the project urgently needs to properly study WebLogic, as an entry-level player can feel the charm of Weblogic
One or two. A clear hierarchy makes it easy to organize the project architecture. The page stream can be used as the core in the Web development process. Combined with the netui control of the presentation layer
A large number of scripts can be converted into simple and easy Object-Oriented Java statements. Whether it's the tree we mentioned above or the data in this article, it's free and not messy.
It is an organic whole. Strong!
I feel that I need to select this book to systematically learn the idea of weblogic.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.