2016-10-18 3 views
0

registrieren Ich versuche, den Admin und andere Benutzer zu registrieren, aber mein Code funktioniert nicht.Kann jemand mir bitte helfen? Dies ist mein Code, den ich verwendet habe, um eine Datenbank zu erstellen und eine Tabelle. Diese ist der Link zum vollständigen Code: http://s000.tinyupload.com/index.php?file_id=71664130076755188207Ich versuche, Benutzer in mysql mit jdbc

public static void main(String[]args)throws Exception {new Aregistration(); 
createTable(); 
} 
//Table 
public static void createTable() throws Exception{ 
    try{ 
     Connection conn = getConnection(); 
     PreparedStatement create = conn.prepareStatement("CREATE TABLE IF NOT EXISTS admin(id int NOT NULL AUTO_INCREMENT,first_name varchar(45),last_name varchar(45),email varchar(320),password varchar(50),PRIMARY KEY(id))"); 
     create.executeUpdate(); 
    }catch(Exception e){System.out.println(e);} 
    finally { 
     System.out.println("System Updated");}; 
} 
//End of Table 
//Database 
public static Connection getConnection() throws Exception{ 

    try{ 
     String driver = "com.mysql.jdbc.Driver"; 
     String url = "jdbc:mysql://localhost:3306/admin?useSSL=false"; 
     String username = "root"; 
     String password = "toor"; 
     Class.forName(driver); 

     Connection conn = DriverManager.getConnection(url,username,password); 
     System.out.println("Connected"); 
     return conn; 
    }catch(Exception e){ 
     System.out.println(e); 
    } 
    return null; 
} 
} 

https://postimg.org/image/ltgqcgqzp/ 
https://postimg.org/image/r65kqlew5/ 
+0

Es gibt kein Problem in dem Code Sie post.But können Sie alle Ihre Code schreiben Wo ist die Klasse Aregistration.And wie Sie den Admin und andere Benutzer registrieren.Was ist die falsche Eingabeaufforderung in der IDE? – lhw1995

Antwort

1

Ähm Ihr Code tut genau das, was es soll ... ich bekomme nicht den Punkt obviusly kippe Sie useres atm einfügen führen, dass Sie nie eine Klasse für diese geschrieben. ..

wie diese:

public static void insertNewUser(String id,String first_name,String last_name, String email,String password){ 
connection conn = getConnection(); 
PreparedStatment create = conn.prepareStatement("Insert into admin Values ?,?,?,?,?"); 
PreparedStatment.setString(1,id); 
PreparedStatment.setString(2,first_name); 
PreparedStatment.setString(3,last_name); 
PreparedStatment.setString(4,email); 
PreparedStatment.setString(5,password); 
PreparedStatment.exectueUpdate(); 

}

Verwandte Themen