Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6222787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:22:37+00:00 2026-05-24T08:22:37+00:00

I am new to jdbc and android. So pardon me if the question seems

  • 0

I am new to jdbc and android. So pardon me if the question seems silly.

I am trying to connect to a MySql database from an app.

I went through the jdbc tutorial and wrote the following code:


 public static void connectToServer () 
{
Connection conn = null;
try
{
//Connect to the database String userName = "********"; String password = "********"; String url = "jdbc:mysql://my.domain.name/myDBname"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); conn = DriverManager.getConnection (url, userName, password); Log.e(tag,"Database connection established"); // Query the database Statement s = conn.createStatement (); String query = "INSERT INTO myTableName (A,B,C)" + "VALUES ('a','b','c')"); Log.e(tag,query); s.executeQuery (query); s.close (); } catch (Exception e) { Log.e(tag,"Database Connection Failed"); Log.e(tag,e.getMessage()); } finally { if (conn != null) { try { conn.close (); Log.e(tag,"Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } }

My manifest code:

< uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

< uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />


The logcat is:

....
Database connection terminated //my output
com.mysql.jdbc.Driver // output from exception e.getMessage()

What am I doing wrong?
Is there a difference between connecting from a java application and android app?


EDIT : Added manifest permissions

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:22:38+00:00Added an answer on May 24, 2026 at 8:22 am

    Be sure you are requesting internet permissions in your manifest.

    EDIT: To do this, add <uses-permission android:name="android.permission.INTERNET" /> to your manifest.

    Just found this link. Not sure if this can be done easily.

    Also something else to look into is CouchDB. Its REST based, so you wouldn’t have to build a php service around the MySQL DB – its purely REST.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add a new JDBC Data Source connect to hive in oracle
I used the following code to connect MySQL in localhost from Android. It only
I have a Java class that accesses a MySQL database through JDBC that I
I have a problem, I am trying to connect to a MySQL database using
I'm new to using JDBC + MySQL. I have several 1/0 values which I
ComboPooledDataSource cpds = new ComboPooledDataSource(); cpds.setDriverClass( com.mysql.jdbc.Driver ); //loads the jdbc driver cpds.setJdbcUrl( jdbc:mysql://localhost:3306/dragon
New to PHP and MySQL, have heard amazing things about this website from Leo
I am new to java and database connections and I am trying to make
I am currently having a problem selecting a certain item from a mySQL database.
I'm new to java and trying to write a simple program using JDBC. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.