Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to connect sql server on android app with including login credentials that includes ip address ,username,password .
here i have multiple database so i need to choose one of the db and work on it !
please help me to overcome this problem !

here i attached my code to connect sql server

What I have tried:

Java
import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;



 public class CONNECT
{
        public static void main(String[] args)
        {

            String connectionUrl =
                    "jdbc:sqlserver://104.211.212.42:1433;databaseName=CONN;integratedSecurity=false";

            String databaseUserName = "admin ";
            String databasePassword = "m";

            try (

                 Connection con = DriverManager.getConnection(connectionUrl, databaseUserName, databasePassword);
                 Statement stmt = con.createStatement())
            {
                String SQL = "SELECT Code,Name FROM COMPANY;";
                ResultSet rs = stmt.executeQuery(SQL);
                while (rs.next())
                {
              String C =   rs.getString("Code");
              String CN = rs.getString("Name");
              System.out.println(C +"-"+ CN);
                }
            }
            catch (SQLException  e)
            {

                System.out.println("Login Failed");
            }

        }

}
Posted
Updated 20-Aug-19 4:08am
v2
Comments
MadMyche 19-Aug-19 14:28pm    
What exactly is the problem when this is executed?

1 solution

Quote:
System.out.println("Login Failed");


How much do you expect to learn about your current situation from the above message when there is more (error) information available? You should learn proper coding "patterns".

Step 3: Proof of concept connecting to SQL using Java - SQL Server | Microsoft Docs[^]
 
Share this answer
 

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