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. It compiled successfully but when I entered the command java TestingDatabase
it said 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. 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$
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.