import java.sql.*;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.text.Format;
import com.mysql.jdbc.Driver;
public class filename {
public static void main(String[] args) throws Exception {
System.out.println("hoi");
Connection con = null;
Statement stmt = null;
String url = "jdbc:mysql://ip:3306/databasename";
ResultSet rs;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
InetAddress ownIP = InetAddress.getLocalHost();
InetAddress address = InetAddress.getByName(ownIP.getHostAddress());
NetworkInterface ni = NetworkInterface.getByInetAddress(address);
if (ni != null) {
byte[] mac = ni.getHardwareAddress();
if (mac != null) {
try {
con = DriverManager.getConnection(url,"username", "password");
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM account WHERE mac1='"+mac[0]+"' AND mac2='"+mac[1]+"' AND mac3='"+mac[2]+"' AND mac4='"+mac[3]+"' AND mac5='"+mac[4]+"' AND mac6='"+mac[5]+"'");
if(rs.first()){
int id = rs.getInt("id");
String mac1 = rs.getString("mac1");
String mac2 = rs.getString("mac2");
String mac3 = rs.getString("mac3");
String mac4 = rs.getString("mac4");
String mac5 = rs.getString("mac5");
String mac6 = rs.getString("mac6");
System.out.println("Exists!");
}else{
System.out.println("Doesn't exist.");
}
con.close();
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
//System.out.println(hoi);
} else {
System.out.println("Address doesn't exist or is not accessible.");
}
} else {
System.out.println("Network Interface for the specified address is not found.");
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
}}