2016-10-18 5 views
0

adminと他のユーザを登録しようとしていますが、私のコードは動作しません。誰でも助けてください?これは私のデータベースですテーブル。 http://s000.tinyupload.com/index.php?file_id=71664130076755188207jdbcを使用してmysqlにユーザを登録しようとしています

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

あなたがあなたのすべてのコードはどこのクラスがあるのpost.Butを投稿することができ、コードには問題はありません:?このような...

Aregistration.Andあなたはどのように管理者や他のユーザーを登録しますか?IDEの間違ったプロンプトは何ですか? – lhw1995

答えて

1

AHMあなたのコードは、それは...私はあなたがこのためにクラスを書いたことはありません原因obviuslyあなたは気圧useresを挿入カントポイントを得るいけない必要があるかを正確に行います。 これは完全なコードへのリンクです。

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(); 

}

関連する問題