Can not issue data manipulation statements with executeQuery in java
Posted
by user225269
on Stack Overflow
See other posts from Stack Overflow
or by user225269
Published on 2010-06-03T07:42:24Z
Indexed on
2010/06/03
7:54 UTC
Read the original article
Hit count: 228
I'm trying to insert records in mysql database using java, What do I place in this code so that I could insert records:
String id;
String name;
String school;
String gender;
String lang;
Scanner inputs = new Scanner(System.in);
System.out.println("Input id:");
id=inputs.next();
System.out.println("Input name:");
name=inputs.next();
System.out.println("Input school:");
school= inputs.next();
System.out.println("Input gender:");
gender= inputs.next();
System.out.println("Input lang:");
lang=inputs.next();
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/employee_record", "root", "MyPassword");
PreparedStatement statement = con.prepareStatement("insert into employee values('id', 'name', 'school', 'gender', 'lang');");
statement.executeUpdate();
© Stack Overflow or respective owner