使用Ucanaccess执行更新查询时访问被拒绝

时间:2019-06-20 15:46:26

标签: java jdbc ucanaccess

我刚刚开始使用ucanaccess,我正在尝试弄清它是如何工作的。我想将Access数据库的用户名从“ Sutaciba”更新为“ Evan”,但显示以下错误:

”发生异常: UCAExc :::: 4.0.4 C:\ Users \ evanc \ AppData \ Roaming \ IT PAT数据库(访问被拒绝)。

Ucanaccess似乎由于某种原因无权访问我的数据库。

谢谢您的帮助!

public static void main(String args[]) 
{
    int ID = 1;
    String username = "Sutachiba";
    String password = "Evanchui123";
    String email = "evanchui34@gmail.com";

   try
    {
      Connection conn = DriverManager.getConnection("jdbc:ucanaccess://C:\\Users\\evanc\\AppData\\Roaming\\IT PAT DataBase");
      Statement s = conn.createStatement();
      ResultSet rs = s.executeQuery("SELECT [username], [password] FROM [tblUser] WHERE ID =" + ID);
      while(rs.next())
      {
          username = rs.getString(1);
          password = rs.getString(2);
          email = rs.getString(3);
          System.out.println("Username: " + username + '\n' + "Password: " + '\n' + "Email:" + email);
      }

      String newN = "Evan";
      String updateQuery = "UPDATE userDB SET (username) = (?) WHERE ID =" + ID;

      PreparedStatement st = conn.prepareStatement(updateQuery);
      st.setString(1, newN);
      st.executeUpdate();
      System.out.println("Successfully updated userdata!");

      conn.close();
    }
    catch(Exception ex)
    {
        System.err.println("Exception occured: ");
        System.err.println(ex.getMessage());
    }

0 个答案:

没有答案