A method for setting the JDBC data source setting of Tomcat559

xiaoxiao2021-03-05  34

Finally, there were many related information early, and there was no success; maybe it's not enough, maybe it is not enough.

Later, the official explanation of Tomcat was passed smoothly. Lessons: Take more official documents.

Although it is simple, it is still written out of the process:

1. MySQL Configuration

Ensure That You Follow these Instructions as variations can Cause Problems.

Create a New Test User, A New Database and A Single Test Table. Your MySQL User Must Have a Password Assigned. The Driver Will Fail If You Try To Connect with an an an an an an an escher password.

MySQL> grant all privileges on *. * to javauser @ localhost

-> Identified by 'javadude' with grant option;

Mysql> Create Database Javates

Mysql> Use javatest;

Mysql> Create Table TestData

-> ID INT NOT NULL AUTO_INCREMENT Primary Key,

-> foo varchar (25),

-> bar int);

NOTE: The Above User Should Be Removed Once Testing IS Complete!

Next INSERT Some Test Data Into The TestData Table.

Mysql> Insert Into TestData Values ​​(Null, 'Hello', 12345);

Query Ok, 1 Row Affected (0.00 sec)

Mysql> Select * from testdata;

-- ------- -----

| ID | foo | BAR |

-- ------- -----

| 1 | Hello | 12345 |

-- ------- -----

1 row in set (0.00 sec)

MySQL>

2. Server.xml Configuration

.

Add this in between the Tag of the example content and the tag closing the localhost definition.

Debug = "5" reloadable = "true" crossContext = "true">

Configure your mysqld max_connections large enough to handle

All of Your DB Connections. Set to 0 for no limit .-->

Set to -1 for no limit. See Also The DBCP Documentation on this

And The MinevictableIdletimeMillis Configuration Parameter.

->

IN ms, in this example 10 seconds. An Exception Is Thrown IF

THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely.

->

Org.gjt.mm.mysql.driver - We Recommend USING CONNECTOR / J Though.

Class Name for the Official MySQL Connector / J Driver is com.mysql.jdbc.driver.

->

The autoreconnect = true argument to the url makess sure what the the URL MAKES SURE THAT

MM.MYSQL JDBC Driver Will Automatically Reconnect IF MySQLD CLOSED THE

Connection. mysqld by Default Closes iDle Connections After 8 Hours.

->

Maxactive = "100" maxidle = "30" maxwait = "10000"

Username = "javauser" password = "javadude" driverclassname = "com.mysql.jdbc.driver"

URL = "JDBC: mysql: // localhost: 3306 / javatest? AutoreConnect = true" />

3. Web.xml Configuration

Now create a web-inf / web.xml for this test application.

XMLns: xsi = "http://www.w3.org/2001/xmlschema-instance"

XSI: schemAlocation = "http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

Version = "2.4">

MySQL Test App

DB Connection

JDBC / TESTDB

javax.sql.datasource

container

4. Test Code

Now Create a Simple Test.jsp Page for Use Later.

<% @ Taglib Uri = "http://java.sun.com/jsp/jstl/sql" prefix = "SQL"%>

<% @ Taglib Uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%>

Select ID, Foo, Bar from testdata

DB Test </ Title></p> <p></ hEAD></p> <p><body></p> <p><H2> Results </ h2></p> <p><c: foreach var = "row" items = "$ r rROWS}"></p> <p>Foo $ {row.foo}</p> <p>Bar $ {row.bar}</p> <p></ c: foreach></p> <p></ body></p> <p></ html></p> <p>. That JSP page makes use of JSTL's SQL and Core taglibs You can get it from Sun's Java Web Services Developer Pack or Jakarta Taglib Standard 1.1 project -. Just make sure you get a 1.1.x release Once you have JSTL, copy jstl.jar And Standard.jar to your Web App's Web-INF / LIB DIRECTORY.</p> <p>Finally Deploy Your Web App INTO $ CATALINA_HOME / WebApps Either As A Warfile Called Dbtest.war or Into a Sub-Directory Called Dbtest</p> <p>Once Deployed, Point A Browser At http: // localhost: 8080 / dbtest / test.jsp to view the fruits of your hard work.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-33783.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="33783" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.036</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'EZzKdOPLEAsK9L6Jw0nvasiXY3YvlsJFbTFSWz_2Bzj31Q_2BJdCFYhYZetdzVnvHZHZazM7mpszrw1JWK1Yx4YFyQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>