ClassNotFoundException on Class.forName(“com.mysql.jdbc.Driver”); [duplicate]

徘徊边缘 提交于 2019-12-13 02:07:03

问题


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;

回答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



来源:https://stackoverflow.com/questions/22991050/classnotfoundexception-on-class-fornamecom-mysql-jdbc-driver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!