String SQL = "INSERT INTO students(id, name, email, gender, status, city) " + Statement = connection.createStatement() User user = new User(5, "Oracle", true, "M", "LHR") Ĭonnection = DriverManager.getConnection("jdbc:mysql://localhost/cuonline", "root", "WriteYourPasswordHere") For each record, database would increment the value by one while inserting new record in table. You noticed, id column is set as 'auto-increment', so it would be automatically initialized if we do not pass its value while inserting new records. ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=latin1 The SQL statement to create the table is given below: I have created a database named cuonline that contains a 'students' table. MySQL Database driver in your classpath, Click Here to Download Connector/J. Before running below examples, you must add Connector/J i.e. Below are the Java code samples that uses Java Database Connectivity API (JDBC) to Create, Retrieve, Update and Delete records using MySQL databases.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |