我正在尝试运行这个 java & mysql 程序,但是当我编译时,它没有显示任何错误。
但是当我运行代码时,它显示了一些异常..
可能是什么错误?
代码:版本.java
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
class Version
{
public static void main(String args[])
{
Connection con = null;
Statement st = null;
String cs = "jdbc:mysql://localhost:3306/google";
String user = "root";
String password = "root";
try {
con = DriverManager.getConnection(cs, user, password);
st = con.createStatement();
String query = "SELECT * FROM user";
st.executeUpdate(query);
}
catch (SQLException ex)
{
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
}
finally
{
try
{
if (st != null)
{
st.close();
}
if (con != null) {
con.close();
}
} catch (SQLException ex)
{
Logger lgr = Logger.getLogger(Version.class.getName());
lgr.log(Level.SEVERE, ex.getMessage(), ex);
}
}
}
}
当我运行代码时,我收到此错误消息
错误信息
Exception in thread "main" java.lang.NoClassDefFoundError: Version
Caused by: java.lang.ClassNotFoundException: Version
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Version. Program will exit.