皆さん、こんにちは。私の投稿をチェックしていただきありがとうございます。Mysql jdbc ドライバーを使用して、サーブレットをデータベースに接続しようとしています。mysql jdbc ドライバーの .jar は、フォルダーapache - tomcat-7.0.27/libにあります。MyServlet はサーブレットであり、接続を確立する必要がある同じフォルダーに SQL.java があります。
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>