I have some remote locations that falls under same domain.When i access the remote location from windows then it opens without asking for credentials.But if i aceess the location using java code (jcifs) then it gives me this exception
jcifs.smb.SmbAuthException: Logon failure: unknown user name or bad
password
Java code is
String path=convertToSmb(loc);
NtlmPasswordAuthentication auth=new NtlmPasswordAuthentication(path, userName, passwd);
SmbFile sFile=null;
try {
sFile=new SmbFile(path,auth);
sFile.connect();
boolean sFileExists = sFile.exists();
logger.info("checkUNCLocation [END] with :: sfileExists :: "+sFileExists);
return sFileExists;
} catch (MalformedURLException e) {
logger.error(e.getMessage(), e);
return Boolean.FALSE;
} catch (IOException e) {
logger.error(e.getMessage(), e);
return UNCNetworkConnectionWrapper.connectUNCNetwork(loc, userName, passwd);
}finally{
sFile=null;
//jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", Boolean.TRUE.toString());
}
i tried deleting all connections using net use delete but windows still did not ask for credentials
Logging also shows correct credentials.
Please guide what should be the reason.
Have you tried to set the userName and the password??
How Windows doing it is by try to connect the server using the current credentials, If you are connected with your user and you are trying to connect to other machine in the same domain, the connection will succeed , because your credentials is valid in this Domain.
Try to use your own credentials to connect to "this" server.
Related
I am having sandbox account of Avalara(Avatax) and that is working fine on my local system and also on the staging environment. But the same sandbox credentials are not working on the UAT instance.
Error logged: avaTaxConnection java.net.SocketException: Connection reset
This is the code snippet I used :
try {
client = new AvaTaxClient("PriceBook", "1.0", "https://sandbox-
rest.avatax.com/api/v2/utilities/ping", AvaTaxEnvironment.Sandbox).withSecurity(PropertiesFileConfiguration.Avatax_AccountID,
PropertiesFileConfiguration.Avatax_LicenseKey);
PingResultModel ping = client.ping();
if (ping.getAuthenticated()) {
return client;
}
} catch (Exception e) {
LOGGER.error("ERROR in avaTaxConnection " + e);
}
When I am trying to get PingResultModel ping on the basis of the client object getting the exception: avaTaxConnection java.net.SocketException: Connection reset.
I have also checked whether the connection is created or not, but the connection is created successfully. I printed the connection object in logs.
I need to check if a FTP server is alive, is this server:
ftp://speedtest.tele2.net/upload/
I tried with this code:
FTPClient ftp = new FTPClient();
try {
ftp.setConnectTimeout(5000);
ftp.setDefaultTimeout(5000);
ftp.setDataTimeout(5000);
ftp.connect(urlString);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
ftp.disconnect();
}
The problem is that is returning this exception:
java.net.UnknownHostException: Unable to resolve host "ftp://speedtest.tele2.net/upload/": No address associated with hostname
How can this be achieved?
The connect method takes a hostname, not a URL.
The ftp:// part is useless; this is an FTP client, it can't do anything else.
The /upload part is also useless; it can't go to that path until after connecting. Hence, taking a URL just doesn't make sense, so the API is properly the designed.
Call .connect("speedtest.tele2.net").
Hello every body I'm working on application which is sends data from android app to MS-SQL server and main windows software in C#, which is receives data from MS-SQl server.
The problem is the programs takes too time to build a connection especially in android app some times it crash the app.
By the way the Internet speed some times goes week in our country.
I searched for a solution but not found in internet and I cannot figure out any way to solve it.
And I see the Viber, Watsapp, Massenger ... etc it sends data instantly or synchronously even if Internet speed is week.
So can I get some help and suggestion.
And there is a connection Helper method :
public Connection connections(){
IP="www.examlple.net";
DB="DB_test";
DBUserName="admin";
DBPassword="*****";
StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection=null;
String connectionURL=null;
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver").newInstance();
connectionURL ="jdbc:jtds:sqlserver://"+IP+";DatabaseName="+DB+";integratedSecurity=true;user="+DBUserName+";password="+DBPassword;
connection = DriverManager.getConnection(connectionURL);
} catch (SQLException | ClassNotFoundException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
}
return connection;
}
For the sake of completeness, with JTDS you can set both a loginTimeout and a socketTimeout on a connection string. Refer to the remarks on these here.
But as others have said, you should go through a web API of some sort. Do you really want to expose your SQL server to the internet?
Also, I just noticed you have specified integrated security=true, and you have also specified a username and password. You can't do that. One is for windows auth (integrated security) and the other is for SQL auth (user and password). You would have to use a username and password. But don't. Don't do this. go through a web API.
I'm trying to connect to my database using sqljdbc4, I'm pretty new to this so i followed a couple of tutorial but it still doesn't seem to work, When i try to run the program i get this Exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ''. ClientConnectionId:f181fd37-7e28-4392-ac86-02914c2090e1
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
And this is my code:
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=DBank;","","");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
You are not passing any authentication credentials. If you want to use integrated security (windows authentication), then you need to explicitly specify that in your connection URL and you need to load the native library required for this.
See Connecting with Integrated Authentication On Windows on Windows on MSDN.
This essentially comes down to including the folder containing the (32 bit or 64 bit) sqljdbc_auth.dll in the java.library.path system property (see link for details) and adding integratedSecurity=true to your connection string:
DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433;databaseName=DBank;integratedSecurity=true");
You are passing empty username and password while connecting to the database in getConnection method:
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=DBank;","","");
Try supplying the db username and password, for example:
DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=DBank;","myusername","mypassword");
I have a problem establishing an connection to my MySql database via Java/Android. I have a database file (MyDatabase.db) on a Windows7 computer in my network. When I'm developing from another Windows7 computer (the file is accessible via the Windows Explorer and I can make changes to the database via SQLDatabaseExplorer) out of Eclipse the following Code works, but when installing my Application on my Galaxy Tab the "DriverManager.getConnection()" returns null.
try {
String url = "http://192.168.178.21/Users/test/userdata/Database/MyDatabase.db";
Class.forName ("com.mysql.jdbc.Driver");
Connection connection = DriverManager.getConnection (url);
System.out.println ("Database connection established");
} catch (SQLException e) {
Log.d("SQLException", "e.toString()");
}
The SQLException logged in LogCat is:
java.sql.SQLException: path to '//192.168.178.21/Users/test/userdata/Database/MyDatabase.db': '/192.168.178.21' does not exist
I guess my problem lies in the url String...? But I did not figure out how to change it, so that the connection can be established.
Thanks for any help,
Tim
EDIT:
Thanks for your help so far! I have written the question yesterday out of my mind, without looking onto my code... I'm sorry for that, because I have mixed up a lot of things... It is not a MySql-database but a sqlite-database... But I think that doesn't change a lot in coding. I'm using an jdbc sqlite driver. When starting the lines below in an Java-Eclipse Project everything works fine and the connection can be established. But on my Device I still got the Nullpointer...
Yesterday I have changed my code so that it should fit your advices. But the problem still resists... To be sure that it does not have to do with some rights or network settings I have copied the DB-File onto my Androiddevice and tried to connect to it directly with the following lines of code:
try {
Class.forName("org.sqlite.JDBC");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection conn = DriverManager.getConnection("jdbc:sqlite://mnt/sdcard/MyVideos34.db");
if (conn == null) {
Log.d("ConnectionError", "Connection is null");
return;
}
But also here getConnection throws a NullPointer and I don't know why... Did somebody have a assumption why the connection can be established out of Eclipse and fails on my Androiddevice? May I could have a wrong driver, that does not work from the device, but from Eclipse...?
Thanks in advance!
The url format for the MYSQL conenction string is
jdbc:mysql://[host][,failoverhost...][:port]/[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
If the host name is not specified, it defaults to 127.0.0.1. If the port is not specified, it defaults to 3306, the default port number for MySQL servers.
jdbc:mysql://[host:port],[host:port].../[database] »
[?propertyName1][=propertyValue1][&propertyName2][=propertyValue2]...
Here is a sample connection URL:
jdbc:mysql://localhost:3306/sakila?profileSQL=true
please change accordingly
JDBC urls have the form : jdbc:mysql:/// but look at the duplicate code. You probably don't want to connect directly to a database from a mobile like this but will prefer a web service wrapper to do it.
try {
String url = "jdbc:mysql://localhost:3306/MyDatabase?user=root&password=root";
Class.forName ("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection (url);
System.out.println ("Database connection established");
} catch (SQLException e) {
System.out.println("SQLException" + e.toString());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}