I configured the data source in the environment of weblogic9.0 + mysql5.1. In fact, the data source configuration function is provided in Tomcat, JBoss, websphere, and other servers. The approximate configuration is similar.
I will briefly describe my configuration and what I should pay attention. Step 1: first we need to download a MySQL driver that must be compatible with your MySQL version and I am using a mysql-connector-java-5.0.7-bin.jar. You can download the driver compatible with your MySQL version online. This step should be very simple and I will not talk about it much. Step 2: add our MySQL driver to your classpath. There are many configuration methods in WebLogic: (Weblogic is installed under E:/BEA) <1>. put it under your E:/BEA/weblogic90/common/lib. We open commenv in the E:/BEA/weblogic90/common/binfile. CMD file. Find the following location: @ REM set up WebLogic Server's class path
Set weblogic_classpath = % patch_classpath %; % java_home %/lib/tools. jar; % wl_home %/Server/lib/weblogic_sp.jar; % wl_home %/Server/lib/weblogic. jar; % wl_home %/common/lib/mysql-connector-java-5.0.7-bin.jar on the end with the mysql-connector-java-5.0.7-bin.jar drive position, where wl_home = E:/BEA/weblogic90, above the red part is newly added. <2>. You can also configure it in the setdomainenv. CMD file under E:/BEA/user_projects/domains/mydomain/bin. Find: Set classpath = % pre_classpath %; % weblogic_classpath %; % post_classpath %; % wlp_post_classpath %; % wl_home %/integration/lib/util. jar; % wl_home %/common/lib/mysql-connector-java-5.0.7-bin.jar on the end with the mysql-connector-java-5.0.7-bin.jar drive position, where wl_home = E:/BEA/weblogic90, above the red part is newly added. <3>. we can also put the mysql-connector-java-5.0.7-bin.jar in the E:/BEA/user_projects/domains/mydomain/lib directory, and then E:/BEA/user_projects/domains/mydomain/bin under setdomainenv. in the CMD file. Find: Set classpath = % pre_classpath %; % weblogic_classpath %; % post_classpath %; % wlp_post_classpath %; % wl_home %/integration/lib/util. jar; % domain_home %/lib/mysql-connector-java-5.0.7-bin.jar on the end with the location of the mysql-connector-java-5.0.7-bin.jar driver, where domain_home = E:/BEA/user_projects/domains/mydomain, the red part above is newly added. <4> You can also directly add the MySQL driver path to the classpath in the computer's environment variable. This is not recommended. From the above we can see that no matter whether the mysql-connector-java-5.0.7-bin.jar is placed there, the key is to finally set its path in classpath. You can go to E:/BEA/weblogic90/common/bin/commenv. in cmd, you can also configure it in E:/BEA/user_projects/domains/mydomain/bin/setdomainenv. in cmd. You can also directly set it in the computer's environment variables. Step 3: create a data source in weblogic. Start the Weblogic server. If we are correctly configured, we can see the last mysql-connector-java-5.0.7-bin.jar on the command console at startup. Open
Http: // localhost: 7001/consoleGo to the console. Click data sources, as shown in figure. Then click New. For example. Then fill in the following information: continue next and fill in the following information. Inherit next and click test configuration to test. If the following information is displayed, the configuration is successful. Finally, you must activate the new data source and click active changes: the 1.1 must be activated: A blogDB-2272-jdbc.xml file is generated under/BEA/user_projects/domains/mydomain/config/jdbc. This file mainly configures the Data source: <? XML version = '1. 0' encoding = 'utf-8'?>
<JDBC-data-source xmlns ="
Http://www.bea.com/ns/weblogic/90"Xmlns: sec ="
Http://www.bea.com/ns/weblogic/90/security"Xmlns: xsi ="
Http://www.w3.org/2001/XMLSchema-instance"Xmlns: WLS ="
Http://www.bea.com/ns/weblogic/90/security/wls"Xsi: schemalocation ="
Http://www.bea.com/ns/weblogic/90/domain.xsd">
<Name> blogdb </Name>
<JDBC-driver-Params>
<URL> JDBC: mysql: // 127.0.0.1: 3306/blog </URL>
<Driver-Name> com. MySQL. JDBC. Driver </driver-Name>
<Properties>
<Property>
<Name> User </Name>
<Value> root </value>
</Property>
</Properties>
<Password-encrypted> {3DES} z0eg + kcsiza = </password-encrypted>
</Jdbc-driver-Params>
<JDBC-connection-pool-Params>
<Test-table-Name> SQL select 1 </test-table-Name>
</Jdbc-connection-pool-Params>
<JDBC-data-source-Params>
<JNDI-Name> blogdb </JNDI-Name>
<Global-transactions-Protocol> onephasecommit </Global-transactions-Protocol>
</Jdbc-data-source-Params>
</Jdbc-data-source> config under E:/BEA/user_projects/domains/mydomain/config. the configuration information of the data source automatically added to the XML file is as follows: <JDBC-system-resource>
<Name> blogdb </Name>
<Target> adminserver </Target>
<Descriptor-file-Name> JDBC/blogDB-2272-jdbc.xml </descriptor-file-Name>
</Jdbc-system-resource> indicates that the configuration is successful. Last step: write a simple test program and test it (index. jsp is located in the project directory): <% @ page Language = "Java" pageencoding = "UTF-8" %>
<% @ Page import = "Java. SQL. *" %>
<% @ Page import = "javax. SQL. *" %>
<% @ Page import = "javax. Naming. *" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> my JSP 'index. jsp 'starting page </title>
</Head>
<Body>
This is my JSP page.
<Br> <%
Initialcontext CTX = new initialcontext ();
Datasource DS = (datasource) CTX. Lookup ("blogdb ");
Connection conn = Ds. getconnection ();
Statement Sm = conn. createstatement ();
Resultset rs = sm.exe cutequery ("select * From bloginfo ");
While (Rs. Next () {system. Out. println ("userid:" + Rs. getstring (1); // user ID
System. Out. println ("username:" + Rs. getstring (2); // User Name
} SM. Close ();
Rs. Close ();
Conn. Close ();
%>
</Body>
</Html> restart the server: Access
Http: // localhost: 7001/weblogicdemo/index. jspIf the output information is displayed, it indicates success: If you want to be helpful to WebLogic friends who are interested, you can reply directly if you do not understand it. Yes.