Skip to content

Instantly share code, notes, and snippets.

@extsalt
Created June 19, 2021 03:56
Show Gist options
  • Save extsalt/080cd3583ba927dac9e4b5d4bb14bacc to your computer and use it in GitHub Desktop.
Save extsalt/080cd3583ba927dac9e4b5d4bb14bacc to your computer and use it in GitHub Desktop.
import java.sql.*;
public class Main {
public static void main(String... args) throws ClassNotFoundException, SQLException {
Connection connection = null;
//Loading of driver
Class.forName("com.mysql.cj.jdbc.Driver");
// Getting connection from driver
connection = DriverManager.getConnection("jdbc:mysql://localhost/srgp?user=root&password=");
// Prepared Statement
PreparedStatement preparedStatement = connection.prepareStatement(
"insert into students (name, e_no, gender, email) values (?, ?, ? ,?)"
);
preparedStatement.setString(1, "Manish Singh");
preparedStatement.setString(2, "21");
preparedStatement.setString(3, "male");
preparedStatement.setString(4, "manish.singh@gmail.com");
preparedStatement.execute();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment