简体   繁体   English

无法找到或加载主类

[英]cannot find or load main class

import java.sql.*;

class TestingDatabase
{
        public static void main(String args[])
        {
            try
            {
                 Class.forName("oracle.jdbc.driver.OracleDriver");
                 Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","metalgear");
                java.util.Scanner input = new java.util.Scanner(System.in);
                int i = input.nextInt();
                PreparedStatement ps = conn.prepareStatement("select * from students where sid=?");
                ps.setInt(1,i);
                ResultSet rs = ps.executeQuery();
                rs.next();
                System.out.println(rs.getInt(1));
                System.out.println(rs.getInt(2));

            }
           catch(ClassNotFoundException e){}
           catch(SQLException e){}
       }
}

I saved this code on desktop and compiled it using javac TestingDatabase.java command.我将此代码保存在桌面上并使用javac TestingDatabase.java命令编译它。 It compiled successfully but when I entered the command java TestingDatabase it said Error: could not find or load main class TestingDatabase它编译成功,但是当我输入命令java TestingDatabase它说Error: could not find or load main class TestingDatabase

I double checked for any spelling mistake but couldn't find one.我仔细检查了拼写错误,但没有找到。 can anyone suggest any solution.任何人都可以提出任何解决方案。

agree with Young Millie on reviewing the list of possible causes.同意 Young Millie 对可能原因列表的审查。 when testing, i found no problem with either the code or executing it.测试时,我发现代码或执行它都没有问题。 i used command line:我使用命令行:

14:31:28$ javac TestingDatabase.java 14:31:33$ java TestingDatabase 14:31:36$ 14:31:28$ javac TestingDatabase.java 14:31:33$ java 测试数据库 14:31:36$

my best guess is that your classpath which might be incorrect;我最好的猜测是您的类路径可能不正确; it should include the current directory (.) at some point or not have a classpath defined at all它应该在某个时候包含当前目录 (.) 或者根本没有定义类路径

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM