Java-MySQL कनेक्शन कोड में एक कॉलम इन्सर्ट करने के लिए INSERT INTO स्टेटमेंट का उपयोग करें।
आइए पहले एक टेबल बनाते हैं:
mysql> create table DemoTable -> ( -> Name varchar(20) -> ); Query OK, 0 rows affected (0.54 sec)
MySQL टेबल में केवल एक कॉलम इन्सर्ट करने का जावा कोड यहाँ है।
उदाहरण
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class InsertOneColumnDemo {
public static void main(String[] args) {
Connection con = null;
PreparedStatement ps = null;
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/web?" + "useSSL=false", "root", "123456");
String query = "insert into DemoTable(Name) values(?) ";
ps = con.prepareStatement(query);
ps.setString(1, "Robert");
ps.executeUpdate();
System.out.println("Record is inserted successfully......");
}
catch (Exception e) {
e.printStackTrace();
}
}
}
इससे निम्न आउटपुट प्राप्त होगा:

अब सेलेक्ट स्टेटमेंट का उपयोग करके टेबल में इन्सर्ट किए गए रिकॉर्ड जांचते हैं:
mysql> select * from DemoTable;
इससे निम्न आउटपुट प्राप्त होगा:
+--------+ | Name | +--------+ | Robert | +--------+ 1 row in set (0.00 sec)