Click here to Skip to main content
15,886,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am creating a web application with a account module. I can successfully login using the below connection and query. Also my TCP/IP is enable and its properties AP Adddress -> IPAll -> TCP Port is set to 1443
Java
public class ConnectionDAO {
    protected Connection conn = null;
    protected PreparedStatement stmt = null;
    protected ResultSet result = null;

    public ConnectionDAO() {
        try {
        	Configuration config = new Configuration();
			Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			this.conn = DriverManager.getConnection("jdbc:sqlserver://" + config.getUrl() + ":1443;databaseName=" + config.getDatabase(), config.getUsername(), config.getPassword());
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
    }
}

public class LoginDAO extends ConnectionDAO {
	
	public LoginDAO() {
		super();
	}

        public UserBEAN getLogin(String username, String password) {
		UserBEAN login = new UserBEAN();
		try {
			result = conn.createStatement().executeQuery("SELECT * FROM [tblLogin] WHERE [username] = '" + username + "'; ");
			while (result.next()) {
				login.setId(result.getInt("ID"));
				login.setUsername(result.getString("username"));
				login.setPassword(result.getString("password"));
				login.setType(result.getInt("type"));
				login.setEncrypted(result.getBoolean("encrypted"));
				if (login.isEncrypted()) {
					login.setPassword(StringCrypt.decypt(login.getPassword(), Global.KEY));
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return login;
	} 
}


But when I'm using prepareStatement to INSERT new user on database I got this error.

<br />
The TCP/IP connection to the host :1443, port 1433 has failed. Error: "null. Verify the connection properties, check that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port, and that no firewall is blocking TCP connections to the port.".<br />


I can successfully create a resultset but prepareStatement is not. Please Help Thanks
Posted
Updated 16-Dec-15 21:49pm
v2

1 solution

SQL Server default port is 1433, not 1443. You're having a typo in your connection string.

Moreover, what is the Class variable you are using in your try..catch block? Shouldn't it be the config variable here instead?
The error message seems to indicate that the config.getUrl() method is returning an empty string.

A debugging session would not be useless.
 
Share this answer
 
Comments
hansoctantan 17-Dec-15 4:20am    
i got this in reading config file
File config = new File(System.getProperty("user.dir") + File.separator + "DDCSupport.config");

in servlet and just a class it has a different return so i got the error. thanks
phil.o 17-Dec-15 5:02am    
Sorry, I don't understand.
Again, launch a debug session and watch for your variables values.
hansoctantan 17-Dec-15 5:51am    
All is running. Thanks
phil.o 17-Dec-15 6:11am    
You're welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900