Я полный нуб и пытаюсь запустить эту программу из командной строки:
import java.sql.*;
import java.util.Scanner;
public class Exp12 {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost:3306/javaexp";
static final String u = "root";
static final String p = "";
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
Connection con = null;
Statement stmt = null;
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(DB_URL, u, p);
stmt = con.createStatement();
System.out.println("Enter the credentials: ");
System.out.print("> Employee Number: ");
int no = in.nextInt();
System.out.print("> Employee Name: ");
String name = in.nextLine();
System.out.print("> Department Number: ");
int dept = in.nextInt();
System.out.print("> Employee Salary: ");
int sal = in.nextInt();
String sql = "INSERT INTO emp VALUES (" + no + ", " + name + ", " + dept + ", " + sal + ")";
stmt.executeUpdate(sql);
}
catch(SQLException sqle) {
sqle.printStackTrace();
}
catch(Exception e) {
e.printStackTrace();
}
finally {
try {
if(stmt != null)
con.close();
}
catch(SQLException sqle1) {
sqle1.printStackTrace();
}
}
}
}
программа компилируется нормально Безошибочная компиляция
Когда я пытаюсь запустить этот код с интерпретатором java, как показано ниже:
code> java -cp [classpath of the .jar mysql driver] Exp12
Я получаю эту ошибку:
could not find or load main class Exp12
Когда я пытаюсь
code>java -cp [classpath of the main class] Exp12
Я получаю:
ClassNotFoundException
Когда я пытаюсь:
code>java -cp [classpath of .jar file]:[classpath of main class] Exp12
Я все еще получаю "Не удалось найти или загрузить основной класс Exp12"
Я установил путь к классу в переменных среды для файла .jar и файла Exp12, но я по-прежнему не могу запустить программу.
Как запустить эту программу?