1

I am working on a android project with eclipse, I have a ClassNotFoundException error on:

Class.forName("com.mysql.jdbc.Driver");

I imported the jar file mysql-connector as is shown in the picture at the link: https://dl.dropboxusercontent.com/u/17360312/Untitled.png

I already put the jar file into libs folder but doesn't work.

Here is the code of the import and package statement of the java file

package com.example.appcani;


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.mysql.jdbc.*;
import prog.doc.prog.io.*;
import prog.io.ConsoleOutputManager;
import prog.io.FileInputManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.os.Build;
user3503810
  • 63
  • 1
  • 1
  • 8
  • Post your stacktrace from the Logcat view in Eclipse so we can help you. – ChuongPham Apr 10 '14 at 14:36
  • Do you really want to connect to MySQL database directly from your Android application? The common pattern is to have server side component running in the server communicating to database using JDBC. Then the Android client communicates with the server using Web Service (e.g. JSON, XML) or other message protocols. – suhe_arie Apr 10 '14 at 14:38
  • I don't know nothing about patterns – user3503810 Apr 11 '14 at 09:41

1 Answers1

1

It seems you are not included jar file for mysql connectivity. you have to do this to include it

Right Click the project -- > build path -- > configure build path

In Libraries Tab press Add External Jar and Select your jar.

You can find zip for mysql here

http://dev.mysql.com/downloads/connector/j/5.0.html

Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76