我想連接並選擇Mule AnypointStudio上的數據庫Sqlite。但它錯誤。請幫幫我。謝謝大家。 發現JDBC沒有合適的驅動程序:sqlite的 這裏我的代碼:錯誤連接Mule連接器中的數據庫Sqlite
@Processor (name="select" ,friendlyName ="select")
public void select() {
ArrayList<Story> list = new ArrayList<Story>();
String sql = "select * from chat";
try (Connection conn = this.connect();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql)){
// loop through the result set
while (rs.next()) {
Story s = new Story();
s.setStory(rs.getInt("id"), rs.getString("user_chat"),rs.getString("bot_chat"));
list.add(s);
}
} catch (SQLException | ClassNotFoundException e) {
System.out.println(e.getMessage());
}
for (int i =0 ; i < list.size(); i++){
System.out.print(list.get(i).GetID() +"| "+ list.get(i).GetUserChat() + "| "+ list.get(i).GetBotChat() +"\n");
}
}
private Connection connect() throws ClassNotFoundException {
// SQLite connection string
Class.forName("org.sqlite.JDBC");
String url = "jdbc:sqlite:C:\\data.db";
Connection conn = null;
try {
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
}
您遇到的錯誤是什麼?請提供詳細信息(堆棧跟蹤,異常消息,任何有用的信息),以便人們可以幫助您。 –
當我運行項目時這是錯誤的。我的連接器找不到Class.forName(「org.sqlite.JDBC」),但我在Mule Project中測試它成功。 java.lang.ClassNotFoundException:org.sqlite.JDBC –
好的。從我的理解你有這個問題與Mule連接器項目。你在使用Maven嗎? –