flydragon111
flydragon111
采纳率35.3%
2016-07-29 09:02

求大神帮帮忙,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条回答

  • pengqihang1009 这只鸟会飞 5年前

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

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

    点赞 评论 复制链接分享
  • bzqweiyi JamesTalk 5年前

    可以用IDEA自动完成。

    点赞 评论 复制链接分享
  • qq_35377583 Humphrey_Hyh 5年前

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

    点赞 1 评论 复制链接分享
  • wangjie037 wangjie037 5年前

    Class.forName不是这样的么?

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

    点赞 1 评论 复制链接分享