Created
June 19, 2021 03:56
-
-
Save extsalt/080cd3583ba927dac9e4b5d4bb14bacc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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