0

I am trying to insert a map object that contains different datatype for "value" option since I have columns with different datatype in database.But I am unable to post this object in database. However I am able to insert data using Arraylist(); in database but I do not know how to use multiple datatypes with that. Here is my code:

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String dated=(dateFormat.format(date));

String Date = dated;
float ENGRO = (float) 10.22;
float AICL = (float) 99.9;
float ACPL = (float) 109.15;

Map<String, Object> map = new HashMap<String, Object>() ;

map.put("Date",dated);
map.put("ENGRO", ENGRO);
map.put("AICL", AICL);
map.put("ACPL", ACPL);
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", (List<NameValuePair>) map);

// check log cat fro response
Log.d("Create Response", json.toString());

// check for success tag
try {
    int success = json.getInt(TAG_SUCCESS);

    if (success == 1) {
       // successfully created product
       Intent i = new Intent(getApplicationContext(), MainActivity.class);
       startActivity(i);

   // closing this screen
   finish();
}   else {
       // failed to create product
}

} catch (JSONException e) {

        e.printStackTrace();
}

        return null;

}

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Anjli Chhatwani
  • 3
  • 1
  • 1
  • 4
  • Just wondering why you have tagged this question with android tag when it has nothing to do with android that I can tell. – tremor Apr 16 '15 at 15:19
  • @tremor I believe the Intent and MainActivity classes are android classes. – Barett Apr 16 '15 at 15:43
  • possible duplicate of [Java connectivity with MySQL](http://stackoverflow.com/questions/2839321/java-connectivity-with-mysql) – Barett Apr 16 '15 at 15:45
  • @tremor : because this code is written in java on android – Anjli Chhatwani Apr 16 '15 at 20:19
  • @Barett: The issue that I am facing is that I want to use multiple datatypes in map object because my columns in table are of different type. – Anjli Chhatwani Apr 16 '15 at 20:22
  • I am posting my php file here – Anjli Chhatwani Apr 16 '15 at 20:23
  • if (isset($_POST['Date']) && isset($_POST['ENGRO']) && isset($_POST['AICL']) && isset($_POST['ACPL'])) { $Date = $_POST['Date']; $ENGRO = $_POST['ENGRO']; $AICL = $_POST['AICL']; $ACPL = $_POST['ACPL']; // include db connect class require_once __DIR__ . '/db_connect.php'; // connecting to db $db = new DB_CONNECT(); // mysql inserting a new row $result = mysql_query("INSERT INTO table2(Date, ENGRO, AICL, ACPL) VALUES('$Date', '$ENGRO', '$AICL' , '$ACPL')"); – Anjli Chhatwani Apr 16 '15 at 20:24
  • Due to the space limitation I have posted only the relevant part of php file – Anjli Chhatwani Apr 16 '15 at 20:27

1 Answers1

0

You won't use PHPMyAdmin, you'll use a direct JDBC connection to insert the data.

See here for the directions on how to connect your app to a database: Connect Java to a MySQL database

Community
  • 1
  • 1
Barett
  • 5,826
  • 6
  • 51
  • 55