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 导入到项目库中,但仍然出现错误:
Could not find or load main class test.Test