Skip to content

Commit b931915

Browse files
committed
insert data
1 parent 9bda690 commit b931915

File tree

8 files changed

+90
-0
lines changed

8 files changed

+90
-0
lines changed

insertData/.classpath

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk-17.0.7.7-hotspot">
4+
<attributes>
5+
<attribute name="module" value="true"/>
6+
</attributes>
7+
</classpathentry>
8+
<classpathentry kind="src" path="src"/>
9+
<classpathentry kind="lib" path="D:/Learnings/Java Full Stack College/mysql-connector-java-8.0.11.jar"/>
10+
<classpathentry kind="output" path="bin"/>
11+
</classpath>

insertData/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>insertData</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=17
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
13+
org.eclipse.jdt.core.compiler.release=enabled
14+
org.eclipse.jdt.core.compiler.source=17
2.37 KB
Binary file not shown.

insertData/bin/module-info.class

169 Bytes
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package insertData;
2+
3+
import java.sql.Connection;
4+
import java.sql.DriverManager;
5+
import java.sql.PreparedStatement;
6+
import java.util.Scanner;
7+
8+
public class insertData {
9+
10+
private static Scanner sc;
11+
12+
public static void main(String[] args) throws Exception { // throws Exception is used to handle the exception without using try-catch block
13+
14+
sc = new Scanner(System.in);
15+
System.out.println("Enter the student details: ");
16+
System.out.print("Enter the student id: ");
17+
int id = sc.nextInt();
18+
System.out.print("Enter the student name: ");
19+
String name = sc.next();
20+
System.out.print("Enter the student branch: ");
21+
String branch = sc.next();
22+
23+
Class.forName("com.mysql.cj.jdbc.Driver"); // load and register the driver
24+
25+
Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3308/jdbc_db", "root", "Akash@123"); // establish the connection
26+
27+
PreparedStatement ps = connection.prepareStatement("insert into student values('"+id+"','"+name+"','"+branch+"')"); // execute the query")
28+
29+
int i = ps.executeUpdate(); // execute the query
30+
if (i > 0) // if the record is inserted successfully then it will return 1 else 0
31+
System.out.println("Record inserted successfully");
32+
else
33+
System.out.println("Record not inserted successfully");
34+
35+
}
36+
37+
}

insertData/src/module-info.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
*
3+
*/
4+
/**
5+
*
6+
*/
7+
module insertData {
8+
requires java.sql;
9+
}

0 commit comments

Comments
 (0)