veryangryman wrote: » I have a mysql database called "bars" on my local PC that i can get to with the following address in my browser.http://localhost/phpmyadmin/db_structure.php?db=bars#PMAURL-0:db_structure.php?db=bars&table=&server=1&target=&token=dc9eefce21adff97525fbf0feb8ccf3e However, i don't know how to code the address of it in the Java code to set up connection. What should be in the below? static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; static final String DB_URL = "jdbc:mysql://localhost/bars";
veryangryman wrote: » Sort of got around this but connection refused. I know this is running on port 3307 and i know the user and password is ok mysql> status C:\Program Files\MySQL\MySQL Server 5.6\bin\mysql.exe Ver 14.14 Distrib 5.6.21, for Win64 (x86_64) Connection id: 15 Current database: Current user: root@localhost SSL: Not in use Using delimiter: ; Server version: 5.6.21-log MySQL Community Server (GPL) Protocol version: 10 Connection: Shared memory: MYSQL Server characterset: utf8 Db characterset: utf8 Client characterset: utf8 Conn. characterset: utf8TCP port: 3307 Uptime: 19 hours 2 min 57 sec But still get done by exception 01-09 11:50:41.611 1913-1913/com.example.user.myapplication W/System.err﹕ java.sql.SQLException: Server connection failure during transaction. Due to underlying exception: 'java.net.SocketException: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 3307): connect failed: ECONNREFUSED (Connection refused)'.
Rebecca Careful Sequel wrote: » Your android app is trying to connect to localhost:3307 ? You have MySql on your laptop!
EamonnDunne wrote: » What others are pointing out is that localhost is only accessible from the local machine, the laptop. Android can't access it using that name. It needs an IP address or hostname. Just also want to point out that having Android connect directly the database is very bad practice, ideally you should be exposing the database using a REST webservice. Regarding doing operations on the main thread which as you have seen is not allowed. You need to learn about AsyncTask developer.android.com/reference/android/os/AsyncTask.html
veryangryman wrote: » So this...? static final String DB_URL = "jdbc:mysql://137.58.72.178:3307/bars?autoReconnect=true"; Agree with point 2 - just want to see how the syntax of code works - will be doing it on a remote web server when app is put out - this is my first time to use a DB in it. It shows
Rebecca Careful Sequel wrote: » I recognise that IP address range, and that signum!, Someone doing side projects in work? :-p If that IP don't allow incomming connections on port 3307 from whever your android connects from, you will still get conmection refused. Are you using your phone or emulator?
EamonnDunne wrote: » Yeah we all now know what company you both work for
veryangryman wrote: » Using the laptop for now.