简体   繁体   中英

ORA-01017 error when attempting to connect to Oracle XE from servlet

I'm trying to write a servlet application for learning purposes that connects to an Oracle database, queries some data and then prints it to the browser. Simple!

However, I'm experiencing an ORA-01017: invalid username/password when attempting to connect to a locally installed and running version of Oracle XE (19c). For the sake of testing the connection, I'm connection with the system user. Here's my code:

// http://localhost:8080/demo/
public class DemoServ extends HttpServlet {

    public void doGet(HttpServletRequest req,HttpServletResponse res)
    throws ServletException,IOException {

        try{
            Class.forName("oracle.jdbc.driver.OracleDriver");
            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1523:xe", "system", "SYSTEM");

            con.close(); 
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The user that I'm using absolutely does exist, and I can connect using SQL Developer without issue.

I would be willing to put this down to my own ignorance of Java, but if I run the following code independently of any servlet, I can connect and execute the sample query!

public class DataReader {

    public static void main (String [] args) {

        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");

            Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1523:xe", "system", "SYSTEM");

            Statement statement = con.createStatement();
            ResultSet rs = statement.executeQuery("SELECT count(*) num FROM dual");

            if (rs.next()) {
                int i = rs.getInt("num"); // get first column returned
                System.out.println("number: " + i);
            }
            rs.close();
            statement.close();
            con.close();
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}

I've been searching Google for solutions to this, but I have been unable to find a solution, so here I am.

I'm working on Windows 10, using Java 1.8 and Oracle 19c XE.

Any help would be great. Thanks

Okay, I finally go this to work, but I cannot explain why.

Oracle 19c is case sensitive, which I knew. I attempted to disable this, but as it's a depreciated feature, this seemed expeditious. I altered the password for the system user to be "system", and I can connect successfully. "SYSTEM" as a password continues to fail.

What strikes me as odd about this is that I'm sure that I tried to use the "system" (lowercase) password in the past. :(

Anyway, I probably was doing something daft, but at least I'm got over the hump. Phew!

Thank you to everyone!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM