java.sql.SQLException: Invalid object name 'tablename' in android studio - android

I'm trying to Make a connection android studio to the database in SQL server 2014 , But this error appears :
java.sql.SQLException: Invalid object name 'tablename'
I use the :jtds 1.3.1
and :sqljdbc4-2.0
I connect a local network .

The SQL statement is failing because you are not using the correct connection URL format for jTDS so you are not actually connecting to the database specified by the String variable serverDb.
You are trying to use a connection URL parameter named database that jTDS does not recognize:
String serverDb = "myDb";
String connUrl = "jdbc:jtds:sqlserver://localhost:49242;database=" + serverDb;
try (Connection conn = DriverManager.getConnection(connUrl, myUid, myPwd)) {
System.out.println(conn.getCatalog()); // prints: master
} catch (Exception e) {
e.printStackTrace(System.err);
}
Instead, you should be using the server:port/database format described in the documentation
String serverDb = "myDb";
String connUrl = "jdbc:jtds:sqlserver://localhost:49242/" + serverDb;
try (Connection conn = DriverManager.getConnection(connUrl, myUid, myPwd)) {
System.out.println(conn.getCatalog()); // prints: myDb
} catch (Exception e) {
e.printStackTrace(System.err);
}

Related

Connecting to Local SQL Server 2008 from my Application

I am working on an Android App for my friend database class and I am a bit in a bind. I am having troubles establishing my connection. Can someone assist me with this? I have a local database, I don't know much about MS SQL server. Here is the information:
ip = "Ip address"; // i am inserting IPV4 IP of computer in this
db = "testing";
un = "xee";
pass = "1995";
port = "1433";
#SuppressLint("NewApi")
public Connection connectionclass(String user, String password, String database, String server)
{
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 +":"+port+";"+ "databaseName=" + db + ";user=" + un + ";password="+ password + ";";
}
catch (SQLException se)
{
Log.e("error here 1 : ", se.getMessage());
}
catch (ClassNotFoundException e)
{
Log.e("error here 2 : ", e.getMessage());
}
catch (Exception e)
{
Log.e("error here 3 : ", e.getMessage());
}
return connection;
}
}
I am getting an error when trying to connect
E/error here 1 :: Network error IOException: failed to connect to /***.***.*.*** (port 1433) from /:: (port 35033): connect failed: ECONNREFUSED (Connection refused)
Is the user name / password definitely correct?
Is your SQL Server configured to 'mixed' authentication mode? https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/change-server-authentication-mode?view=sql-server-2017
Does the user account have sufficient permissions to access the database? Try setting the login account to be 'sysadmin', which will give it maximum privileges.
Check the Firewall (not if it's a local DB)

How to connect my app to a SQL Server database?

How to connect Android app to a SQL Server database?
I want to make an Android login that connects to sql server but I am confused to make a connection from Android to sql server
First, download the driver from this link and place it at the following address
https://sourceforge.net/projects/jtds/
Next you need to introduce the location of the above file in Gardel:
Complite file ('libs / jtds-1.3.1.jar)
Then create a class with the desired name and in it create values ​​(username and password and database name and IP name) of the string type
public class sqlConnectionToSQL {
// Database Username
String userName;
// Database Password
String password;
// Connection builder class
String classes;
// Site or Local IP
String ip;
}
Then create the connection function in this way and put the following code in it
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder ();
StrictMode.setThreadPolicy (policy);
Connection conn = null;
String connURL = null;
try
{
Class.forName (classes)
connURL = "jdbc: jtds: sqlserver: //" + ip + ": 1433" + "; databasename:" + db + "; Username:" + userName + "; Password:" + password + ";";
conn = DriverManager.getConnection (connURL);
} Catch (ClassNotFoundException e) {
Log.e (e.getMessage (), "Error:");
} Catch (sqlException e) {
Log.e (e.getMessage (), "Error:");
}
Connection Catch (Exception e) {
Log.e (e.getMessage (), "Error:");
}
return conn;
}
This is the way to connect the database to Android

MongoDB on Android - socket timeout

I want to connect my Android app to remote MongoDB database:
try {
String str = "";
MongoClientURI uri = new MongoClientURI("mongodb://byulent:mypass#ds231549.mlab.com:31549/mydb");
MongoClient mongoClient = new MongoClient(uri);
MongoDatabase db = mongoClient.getDatabase(uri.getDatabase());
MongoCollection<Document> photos = db.getCollection("photos");
FindIterable<Document> cursor = photos.find();
Iterator i = cursor.iterator();
while (i.hasNext()){
Log.d("obj", i.next().toString());
}
//Toast.makeText(context, "Succesfully connected to MongoDB", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Log.e("mongodb", e.getMessage());
}
But when I try to get data from DB, I see this error:
E/mongodb: Timed out after 30000 ms while waiting to connect. Client view of cluster state
is {type=UNKNOWN, servers=[{address=ds231549.mlab.com:31549, type=UNKNOWN, state=CONNECTING,
exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by
{java.net.SocketTimeoutException: failed to connect to ds231549.mlab.com/34.245.70.193
(port 31549) after 20000ms}}]
Why this error occurs and how to fix it?

Android - Connecting MS SQL Server 2008 R2 - Error Connection NULL - Eclipse

I'm new to android. When I try to connect my android app to MS SQL Server database using eclipse android emulator, the LogCat showed me the exception "Error Connection - NULL". I've searched many posts over the internet related to this issue but yet to get a solution for that.
Here is my code which try to connect to database after i click a button. I have copy jtds-1.2.7.jar into the libs folder. Also, set the permission to INTERNET in my manifest file. Can anyone let me know what's wrong with that? Please ~~
public void onClick1(View view) {
Log.i("Android"," MySQL Connect Example.");
Connection conn = null;
try {
String driver = "net.sourceforge.jtds.jdbc.Driver";
Class.forName(driver).newInstance();
String connString = "jdbc:jtds:sqlserver://serverIP:1435/db_name;encrypt=fasle;user=xxxxxx;password=!xxxxxx;instance=SQLEXPRESS;";
String username = "xxxxxx";
String password = "!xxxxxx";
conn = DriverManager.getConnection(connString,username,password);
Log.w("Connection","open");
Statement stmt = conn.createStatement();
ResultSet reset = stmt.executeQuery("select * from xxxxxx");
//Print the data to the console
while(reset.next()){
Log.w("Data:",reset.getString(3));
}
conn.close();
} catch (Exception e)
{
Log.w("Error connection","" + e.getMessage());
}
}
LogCat - After throw a lot of garbage, showing Error Connection, NULL

Android database connectivity exception

I am trying to make an android (2.3) connection with MySQL. The code is below:
public class ConnectionClass {
static String user = "root";
public static void main() {
String url = "jdbc:mysql://127.0.0.1:3306/mydatabase";
// String url = "jdbc:mysql://10.2.5.69:3306/test";
try {
Class.forName("com.mysql.jdbc.Driver");
***Connection con = DriverManager.getConnection(url, user, "mypassword");***
con.isReadOnly();
System.out.println("success");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from user");
while (rs.next()) {
System.out.println("id" + rs.getInt(1));
System.out.println("data" + rs.getString(2));
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
but at the line Connection con = DriverManager.getConnection(url, user, "mypassword") I get the exception:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Well I didnt find anything wrong with your code..
But if you want to connect to mysql at any cost,I would suggest an alternate method of using php as an mediator, which can do all the operations which is mentioned and accessing this php file though HttpClient in java
ref:http://www.helloandroid.com/tutorials/connecting-mysql-database
Android doesn't support for MySQL database.
See the official documentation here:
http://developer.android.com/guide/topics/data/data-storage.html#db

Categories

Resources