Edit context. XML in the project. If no, create context. xml.
1. Context. xml
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <context antijarlocking = "true" Path = "/Python" reloadable = "true"> <br/> <Resource Name = "JDBC/jsp_manage" auth = "Container "<br/> type =" javax. SQL. datasource "<br/> maxactive =" 100 "maxidle =" 30 "maxwait =" 10000 "<br/> username =" root "Password =" 123456 "<br/> driverclassname = "com. mySQL. JDBC. driver "<br/> url =" JDBC: mysql: // localhost: 3306/jsp_manage? Authreconnect = true "/> <br/> </context>
Characterencoding = UTF-8, set the database Encoding
2. Connection Pool case
Package JDBC. util; <br/> Import Java. SQL. connection; <br/> Import Java. SQL. sqlexception; <br/> Import javax. naming. initialcontext; <br/> Import javax. naming. namingexception; <br/> Import javax. SQL. datasource; <br/> public class dbutil {<br/> Private Static datasource DS = NULL; </P> <p> static {<br/> initialcontext CTX; <br/> try {<br/> CTX = new initialcontext (); <br/> DS = (datasource) CTX. lookup ("Java: COMP/ENV/jdbc/Bookstore"); <br/>} catch (namingexception E) {<br/> // todo auto-generated Catch Block <br/> E. printstacktrace (); <br/>}</P> <p> private void dbutil () {}</P> <p> Public static connection getconnection () throws sqlexception {<br/> return Ds. getconnection (); <br/>}< br/>