TP 10 Accessing Data Bases With JDBC
TP 10 Accessing Data Bases With JDBC
Add a new class in the project named Driver and check the option for
including the main () function.
Add the driver downloaded earlier creating first a new folder named lib in
your project (right click on the name of the project) and in this folder add the
mysql-connector-java-5.1.34-bin.jar (drag and drop)
Right click on the name of the project testJDBC and Properties/Java Build
Path/Add JARs (from label Libraries) and select .jar from lib, then OK.
Be aware that the password for the root is you that establish!
10.6. Inserting records
You can use another project and insert the following code:
import java.sql.*;
public class Driver {
/**
* @param args
*/
public static void main(String[] args) {
try{
//DB connection
Connection myConn =
DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "pass");
//Query
//Execution
String sql = "insert into book(idBook, Name, Author) values ('3','The Brothers Karamazov',
'Dostoevsky')";
myStmt.executeUpdate(sql);
TO DO: Write the Java code for updating and deleting records from your
database.