package test;
import java.sql.*;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
try{
Scanner sc = new Scanner(System.in);
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/database", "root", "root");
Statement stmt = (Statement) con.createStatement();
System.out.print("Enter name to search");
String name = sc.next();
String query = "SELECT * FROM Contacts WHERE first_name = '" + name + "' ;";
ResultSet rs = stmt.executeQuery(query);
while(rs.next()){
System.out.println("Last_Name: " + rs.getString("last_name"));
System.out.println("First_Name: " + rs.getString("first_name"));
System.out.println("Email: " + rs.getString("email"));
System.out.println("Phone: " + rs.getString("mobile_phone"));
}
} catch(Exception e){
System.out.println("ERROR: " + e.
}
我進口了jdbc.jar進入項目庫,並仍然得到錯誤:無法找到或加載主類test.Test
Could not find or load main class test.Test
這看起來並不像一個編譯器錯誤,但像運行時錯誤。你如何開始你的計劃? – 2013-04-20 15:31:48
我猜你正在從錯誤的文件夾運行你的程序。 – NilsH 2013-04-20 15:34:43
我使用NetBeans,我也在cmd javac中嘗試過,但它給出了相同的錯誤。 – user2302448 2013-04-20 15:40:18