我在jdbc上工作时遇到错误

时间:2013-12-09 05:34:35

标签: java mysql sql jdbc

编译JDBC程序时我遇到了这个错误

计划代码

public static void main(String[] args) {

        Connection conn=null;
        Statement stat=null;
        ResultSet rs = null;

        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            conn =  (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/cricket","root","root");
            stat = ((java.sql.Connection) conn).createStatement();
            rs = stat.executeQuery("SELECT Cric_id,Cric_name,Normal_Skilla,Special_Skill,Other_Skill FROM indian");

            while(rs.next())
            {
                int id = rs.getInt("Cric_id");
                String name = rs.getString("Cric_name");
                String normal = rs.getString("Normal_Skills");
                String special = rs.getString("Special_Skill");
                String other = rs.getString("Other_Skill");

                System.out.println(id +"\t"+name+"\t"+normal+"\t"+special+"\t"+other);
            }
        }catch(Exception e)
        {
            System.out.println("Error:"+e);
        }
        finally
        {
            if(conn != null)
                try{
                    conn.close();
                }catch(Exception ig)
                {
                    System.out.println("ERROR2:"+ig);
                }
        }

    }

}

错误

Exception in thread "main" java.lang.NoClassDefFoundError: JDBC1 (wrong name: jdbc1)
    at java.lang.ClassLoader.findBootstrapClass(Native Method)
    at java.lang.ClassLoader.findBootstrapClassOrNull(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

我正在使用Eclipse IDE,任何人都可以看到我错在哪里

3 个答案:

答案 0 :(得分:0)

您的查询中没有名为Normal_Skills的列。 改变

  String normal = rs.getString("Normal_Skills");

  String normal = rs.getString("Normal_Skilla");

反之亦然。

答案 1 :(得分:0)

这可能是因为您没有代码中选择的驱动程序的jar文件。

对于“com.mysql.jdbc.Driver”,使用此驱动程序下载jar文件并添加到项目中并尝试再次执行。

您可以从http://www.mysql.com/products/connector/

下载jar

答案 2 :(得分:0)

试试这个,

try
        {
            Class.forName("com.mysql.jdbc.Driver");
            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/cricket","root","root");
            stat = conn.createStatement();
            rs = stat.executeQuery("SELECT Cric_id,Cric_name,Normal_Skilla,Special_Skill,Other_Skill FROM indian");