求大神帮帮忙,eclipse开发中,用jdbc连接数据库,加载驱动运行报错

这是我加载驱动的代码:
String sql="select * from parkinfo where city='"+myCity+"'";
Random random=new Random();
try {
Class.forName("org.gjt.mm.mysql.Driver");

            conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/park", "root", "root");
            //PreparedStatement pst=conn.prepareStatement(sql);
            //pst.setString(1, myCity);
            //ResultSet rs=pst.executeQuery();
            Statement st=conn.createStatement();
            ResultSet rs=st.executeQuery(sql);
            int remain=random.nextInt(rs.getInt("space"));
            List<Info> myCityInfo=new ArrayList<Info>();
            if(rs.next()){
                myCityInfo.add(new Info(rs.getDouble("latitude"), rs.getDouble("longitude"), 
                        R.drawable.my_car, rs.getString("name"), rs.getString("address"), 
                        remain, rs.getInt("charge"), rs.getInt("reserve")));

            }
            addOverlays(myCityInfo);
            st.close();
            conn.close();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

已经为MySQL包(jar)添加路径了,运行时控制台console出现下面情况,看不到的错误啊
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:188)
at com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:786)
at com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:597)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:726)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
at org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
at org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
at org.eclipse.core.internal.resources.Project.build(Project.java:124)
at com.android.ide.eclipse.adt.internal.project.ProjectHelper.doFullIncrementalDebugBuild(ProjectHelper.java:1143)
at com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:155)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:855)
at org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:704)
at org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:1047)
at org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1251)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)
...while parsing com/mysql/jdbc/JDBC42CallableStatement.class
[2016-07-29 16:52:00 -MySQL] Dx 1 error; aborting
[2016-07-29 16:52:00 -MySQL] Conversion to Dalvik format failed with error 1

4个回答

哥们,貌似不是你的数据库驱动的问题。参考一下这个吧:http://stackoverflow.com/questions/24662801/bad-class-file-magic-or-version

另:你用的数据库驱动是不是有点老了?org.gjt.mm.mysql.Driver 是早期的驱动名称,后来就改名为com.mysql.jdbc.Driver,现在一般都推荐使用com.mysql.jdbc.Driver

st1466096322
st1466096322 回复flydragon111: 我也碰到了这个问题,可以说明一下是怎么解决的吗
接近 2 年之前 回复
st1466096322
st1466096322 我也碰到了这个问题,可以说明一下是怎么解决的吗
接近 2 年之前 回复
flydragon111
flydragon111 谢谢,确实是版本问题
3 年多之前 回复

Class.forName不是这样的么?

Class.forName(“com.mysql.jdbc.Driver”);

flydragon111
flydragon111 谢谢谢谢,我的版本问题,
3 年多之前 回复

你反射的Class.forName()里面的驱动名字不对吧

flydragon111
flydragon111 我的版本问题,解决了谢谢哈
3 年多之前 回复

可以用IDEA自动完成。

flydragon111
flydragon111 解决了,谢谢哈
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问