gpt4 book ai didi

java - 在 jdbc 上工作时,我在 eclipse 中遇到错误

转载 作者:行者123 更新时间:2023-11-30 23:09:29 24 4
gpt4 key购买 nike

在编译 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 任何人都可以看到我错在哪里

最佳答案

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

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

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

反之亦然。

关于java - 在 jdbc 上工作时,我在 eclipse 中遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20463820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com