問候大家,並感謝您檢查我的帖子。我試圖通過使用Mysql jdbc驅動程序將我的servlet與我的數據庫連接起來。我的.jar來自mysql jdbc驅動程序位於文件夾apache-tomcat-7.0.27/lib。 MyServlet是一個servlet,我在連接必須建立的同一個文件夾中有SQL.java。無法連接到數據庫(錯誤:`com.mysql.jdbc.Driver`)
private static Connection conn = null;
Class.forName(driver).newInstance();
conn = (Connection)
DriverManager.getConnection("jdbc:mysql://"+"localhost:3306"+"/"+ "ergasia3", "root" , "spiros");`
不幸的是,當我嘗試這樣做,我有一個錯誤:com.mysql.jdbc.Driver
。
這裏是我的web.xml
<web-app>
<display-name>WebApp01</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>com.srk.pkg.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet.do</url-pattern>
</servlet-mapping>
<resource-ref>
<description>database</description>
<res-ref-name>jdbc/ergasia3</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
,現在我的context.xml
<Context path="/ergasia3" docBase="ergasia3"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/ergasia3" auth="Container"
type="javax.sql.DataSource"
user="root" password="spiros"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/ergasia3"
maxActive="15" maxIdle="3" />
</Context>
請問您能更具體嗎?還是您能給我一條路? – Romanos
YourProjectDir> WebContent> WEB_INF> lib ..然後刷新項目。如果不起作用,請右鍵單擊您的項目(在Eclipse IDE中)並單擊屬性。然後單擊JavaBuildPath並選擇Libraries選項卡添加JAR(在此處添加MySQL連接器) –
您可以選中此鏈接(http://stackoverflow.com/questions/11193311/jdbc-error-when-connecting-tomcat-5-5- to-sql-2008-what-am-i-missing)相同類型的問題和答案。 –