我在设计用于返回列表字符串(从 DB 中选择) @Webservice的 JDBC 连接 Webservice(Axis2)时遇到问题
public ArrayList<String> loadDatabase(String txtSearch) {
ArrayList<String> myList = new ArrayList<>();
Connection con = null;
Statement st = null;
ResultSet rs = null;
String url = "jdbc:mysql://127.0.0.1:3306/smd";
String user = "root";
String password = "passw0rd";
try {
con = DriverManager.getConnection(url, user, password);
st = con.createStatement();
rs = st.executeQuery("SELECT VERSION()");
rs = st.executeQuery("Select * FROM medicine");
while (rs.next()) {
String name = rs.getString("NAME");
myList.add(name);
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
} finally {
try {
if (rs != null) {
rs.close();
}
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex) {
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.WARNING, ex.getMessage(), ex);
}
}
return myList;
}
@客户
public static void main(String[] args) {
try {
ArrayList<String> addData = new ArrayList<String>();
MedicineJDBCFinderStub mStub = new MedicineJDBCFinderStub();
MedicineJDBCFinderStub.LoadDatabase stub = new MedicineJDBCFinderStub.LoadDatabase();
stub.setTxtSearch("t");
LoadDatabaseResponse result = mStub.loadDatabase(stub);
} catch(Exception ex) {
ex.printStackTrace();
}
}
我部署成功,但是当我在 Client 中运行 Main 类或在 Android 上运行(使用 KSOAP)时,我遇到了同样的问题
SEVERE: No suitable driver found for jdbc:mysql://127.0.0.1:3306/smd
java.sql.SQLException: No suitable driver found for jdbc:mysql://127.0.0.1:3306/smd
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.med.dic.finder.MedicineJDBCFinder.loadDatabase(MedicineJDBCFinder.java:27)
虽然我将 mysql-connector-java-5.1.25-bin.jar 添加到库并在 Main 中成功连接(不使用 Webservice)。
任何人都可以帮我解决问题吗?非常感谢