问题描述
大家看看,struts2中配置Tomcat数据源究竟哪有问题?BbPool.java文件++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++packageorg;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importjavax.naming.Context;importjavax.sql.DataSource;publicclassDbPool{privateConnectionconn;publicvoidcreateConn(){try{ContextinitCtx=newjavax.naming.InitialContext();ContextenvCtx=(Context)initCtx.lookup("java:comp/env");//java:comp/env是环境命名上下文DataSourceds=(DataSource)envCtx.lookup("jdbc/DBPool");conn=ds.getConnection();System.out.println("数据库连接成功!");}catch(Exceptione){System.out.println("数据库连接失败!");}}publicConnectiongetConn(){if(conn==null){createConn();}returnconn;}publicResultSetaaa(Stringsql){ResultSetrs=null;if(conn==null){createConn();}try{Statementst=this.conn.createStatement();rs=st.executeQuery(sql);}catch(SQLExceptione){e.printStackTrace();}returnrs;}}dbPool.jsp文件+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"%><%@pageimport="org.DbPool"%><%@pageimport="java.sql.*"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>MyJSP'dbPool.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body><%DbPooldbp=newDbPool();Stringsql="SELECT*FROMperson";ResultSetrs=dbp.aaa(sql);while(rs.next()){out.print(rs.getInt(1));out.print(rs.getString(2));out.print(rs.getInt(3));out.print(rs.getString(4));out.print("<br/>");}%></body></html>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++下面是context.xml文件+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<?xmlversion='1.0'encoding='UTF-8'?><Context><Resourcename="jdbc/DBPool"auth="Container"type="javax.sql.DataSource"username="root"password="admin"maxIdle="30"maxAction="100"maxWait="5000"driverClassName="com.mysql.jdbc.Dirver"url="jdbc:mysql//localhost:3306/user"/></Context>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++控制台错误信息java.lang.IllegalArgumentException:Unmatchedbracesinthepattern.atjava.text.MessageFormat.applyPattern(UnknownSource)atjava.text.MessageFormat.<init>(UnknownSource)atjava.text.MessageFormat.format(UnknownSource)atorg.eclipse.jdt.internal.core.util.Messages.bind(Messages.java:388)atorg.eclipse.jdt.internal.core.util.Messages.bind(Messages.java:354)atorg.eclipse.jdt.internal.core.util.Disassembler.disassemble(Disassembler.java:883)atorg.eclipse.jdt.internal.core.util.Disassembler.disassemble(Disassembler.java:290)atorg.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor$SourceAttachmentForm.updateCodeView(ClassFileEditor.java:403)atorg.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor$SourceAttachmentForm.createControl(ClassFileEditor.java:207)atorg.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor.verifyInput(ClassFileEditor.java:764)atorg.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor.createPartControl(ClassFileEditor.java:714)atorg.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:661)atorg.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:426)atorg.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:592)atorg.eclipse.ui.internal.EditorReference.getEditor(EditorReference.java:263)atorg.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2739)