我正在開發一個Java的Web服務,它與MySQL數據庫進行交互。我已經開發了對java中的databse和Mysql中的存儲過程的請求......但通信不起作用。我總是收到此錯誤:Java和mysql通信
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/madrim
我正在使用Tomcat服務器在JAVA中的Web服務使用Windows。我下載了mysql驅動程序(「mysql-connector-java-5.1.20-bin.jar」)並添加到tomcat的文件夾中(〜\ Tomcat 7.0 \ lib),但它什麼也沒做。
它可能是什麼?任何提示?
這裏有點代碼...:
Connection con = null;
Statement st = null;
ResultSet rs = null;
try
{
con = DriverManager.getConnection(DB_URL, DB_USER_NAME, DB_PASSWORD);
st = con.createStatement();
String query = BuildQuery();
rs = st.executeQuery(query);
returnObj.SetResult(rs);
}
catch (SQLException ex)
{
returnObj.SetException(DataException.SQL);
}
墜毀並去捕捉。
編輯:更多的東西。
的Tomcat的context.xml:
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<Resource name="jdbc/madrim"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="asdf"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/madrim"
maxActive="15"
maxIdle="3"/>
</Context>
而該項目的WEB-INF/web.xml文件:
<resource-ref>
<description>AccesoBaseDeDatos</description>
<res-ref-name>jdbc/madrim</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
如果你向我們展示你的代碼的問題區域,它將幫助潛在的回答者。 –
檢查http://stackoverflow.com/questions/8946088/set-default-classpath-to-use-in-java-command-in-command-prompt/8946331#8946331/set-default-classpath-to-use- in-java-command-in-command-prompt/8946331#8946331 –
@ user1042031 IMO不是非常有用 - 這是一個web應用程序,我們不知道OP如何嘗試初始化驅動程序。 –