Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 361bdbd

Browse files
some more codes of spring
1 parent 7bb5ee4 commit 361bdbd

File tree

9 files changed

+205
-5
lines changed

9 files changed

+205
-5
lines changed

‎Spring Projects/firstprogram/pom.xml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>com.myfirstProgram</groupId>
@@ -33,14 +34,24 @@
3334
<artifactId>mysql-connector-java</artifactId>
3435
<version>5.1.47</version>
3536
</dependency>
37+
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
3638

3739

3840

41+
42+
<dependency>
43+
<groupId>org.springframework</groupId>
44+
<artifactId>spring-jdbc</artifactId>
45+
<version>5.3.22</version>
46+
</dependency>
47+
3948
<dependency>
4049
<groupId>junit</groupId>
4150
<artifactId>junit</artifactId>
4251
<version>3.8.1</version>
4352
<scope>test</scope>
4453
</dependency>
4554
</dependencies>
55+
56+
4657
</project>

‎Spring Projects/firstprogram/src/main/java/com/spring/annotation/autowiring/AutoWireConfig.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
https://www.springframework.org/schema/context
99
https://www.springframework.org/schema/context/spring-context.xsd">
1010

11-
<bean name="address" class="com.spring.annotation.autowiring.Address">
11+
<bean name="address" class="com.spring.annotation.autowiring">
1212
<property name="street" value="alpha-1"/>
1313
<property name="city" value="Gr noid"/>
1414

1515
</bean>
1616
<bean class="com.spring.annotation.autowiring.Emp" name="objEmp" autowire="byName"/>
17-
17+
]
1818
</beans>
1919

‎Spring Projects/firstprogram/src/main/java/com/spring/annotation/autowiring/Test.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ public class Test {
77
public static void main(String[] arg) {
88
ApplicationContext context=new ClassPathXmlApplicationContext("com/spring/annotation/autowiring/AutoWireConfig.xml");
99
Emp emp1=(Emp)context.getBean("objEmp",Emp.class);
10-
System.out.println("\n\n"+emp1);
11-
10+
System.out.println("\n\n"+emp1);
1211
}
13-
1412
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:p="https://www.springframework.org/schema/p"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation=" http://www.springframework.org/schema/beans
7+
https://www.springframework.org/schema/beans/spring-beans.xsd
8+
https://www.springframework.org/schema/context
9+
https://www.springframework.org/schema/context/spring-context.xsd">
10+
11+
<bean name="objDS "
12+
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
13+
14+
<property name="driverClassName" value="com.spring.jdbc.Driver" />
15+
<property name="url" value="jdbc:mysql://localhost:3306/springjdbc" />
16+
<property name="username" value="root"/>
17+
<property name="password" value="Amsan@2003"/>
18+
</bean>
19+
20+
21+
<bean name="objJdbcTemplet" class="com.spring.jdbc.JdbcTemplate">
22+
<property name="dataSource" ref="objDS"/>
23+
24+
25+
</beans>
26+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.spring.jdbc;
2+
3+
public class Student {
4+
private int sId;
5+
private String sName;
6+
private String sCity;
7+
public Student() {
8+
9+
}
10+
public Student(int sId, String sName, String sCity) {
11+
this.sId = sId;
12+
this.sName = sName;
13+
this.sCity = sCity;
14+
}
15+
public int getsId() {
16+
return sId;
17+
}
18+
public void setsId(int sId) {
19+
this.sId = sId;
20+
}
21+
public String getsName() {
22+
return sName;
23+
}
24+
public void setsName(String sName) {
25+
this.sName = sName;
26+
}
27+
public String getsCity() {
28+
return sCity;
29+
}
30+
public void setsCity(String sCity) {
31+
this.sCity = sCity;
32+
}
33+
34+
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.spring.jdbc;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
import org.springframework.jdbc.core.JdbcTemplate;
6+
7+
import com.spring.jdbc.dao.StudentDao;
8+
import com.spring.jdbc.entities.Student;
9+
10+
public class Test {
11+
public static void main(String[] arg) {
12+
//spring jdbc-->jdbcTemplet
13+
ApplicationContext context=new ClassPathXmlApplicationContext("com/spring/jdbc/JdbcConfig.xml");
14+
JdbcTemplate templet=(JdbcTemplate)context.getBean("objJdbcTemplet",JdbcTemplate.class);
15+
//Insert query
16+
String query="insert into student(id,name,city) values(?,?,?)";
17+
int i=templet.update(query,22,"Rahul","Delhi");
18+
System.out.println("NO of row inserted!!"+i);
19+
//select query
20+
21+
22+
System.out.println("------Listing Multiple Records--------" );
23+
List<Student> students = template.listStudents();
24+
25+
for (Student record : students) {
26+
System.out.print("ID : " + record.getId() );
27+
System.out.print(", Name : " + record.getName() );
28+
System.out.println(", Age : " + record.getCity());
29+
}
30+
}
31+
32+
}
33+
34+
35+

‎jdbcsimple/JdbcConfig.xml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans"
3+
xmlns:p="https://www.springframework.org/schema/p"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:context="http://www.springframework.org/schema/context"
6+
xsi:schemaLocation=" http://www.springframework.org/schema/beans
7+
https://www.springframework.org/schema/beans/spring-beans.xsd
8+
https://www.springframework.org/schema/context
9+
https://www.springframework.org/schema/context/spring-context.xsd">
10+
11+
<bean name="objDS "
12+
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
13+
14+
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
15+
<property name="url" value="jdbc:mysql://localhost:3306/springjdbc" />
16+
<property name="username" value="root"/>
17+
<property name="password" value="sps@133"/>
18+
</bean>
19+
20+
21+
<bean name="objJdbcTemplet" class="org.springframework.jdbc.core.JdbcTemplate">
22+
<property name="dataSource" ref="objDS"/>
23+
24+
25+
</beans>
26+

‎jdbcsimple/Student.java‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.springcore.jdbc.simple;
2+
3+
public class Student {
4+
private int sId;
5+
private String sName;
6+
private String sCity;
7+
public Student() {
8+
9+
}
10+
public Student(int sId, String sName, String sCity) {
11+
this.sId = sId;
12+
this.sName = sName;
13+
this.sCity = sCity;
14+
}
15+
public int getsId() {
16+
return sId;
17+
}
18+
public void setsId(int sId) {
19+
this.sId = sId;
20+
}
21+
public String getsName() {
22+
return sName;
23+
}
24+
public void setsName(String sName) {
25+
this.sName = sName;
26+
}
27+
public String getsCity() {
28+
return sCity;
29+
}
30+
public void setsCity(String sCity) {
31+
this.sCity = sCity;
32+
}
33+
34+
35+
}

‎jdbcsimple/Test.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.springcore.jdbc.simple;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
import org.springframework.jdbc.core.JdbcTemplate;
6+
7+
import com.spring.jdbc.dao.StudentDao;
8+
import com.spring.jdbc.entities.Student;
9+
10+
public class Test {
11+
public static void main(String[] arg) {
12+
//spring jdbc-->jdbcTemplet
13+
ApplicationContext context=new ClassPathXmlApplicationContext("com/spring/jdbc/JdbcConfig.xml");
14+
JdbcTemplate templet=(JdbcTemplate)context.getBean("objJdbcTemplet",JdbcTemplate.class);
15+
//Insert query
16+
String query="insert into student(id,name,city) values(?,?,?)";
17+
int i=templet.update(query,22,"Rahul","Delhi");
18+
System.out.println("NO of row inserted!!"+i);
19+
//select query
20+
21+
22+
System.out.println("------Listing Multiple Records--------" );
23+
List<Student> students = template.listStudents();
24+
25+
for (Student record : students) {
26+
System.out.print("ID : " + record.getId() );
27+
System.out.print(", Name : " + record.getName() );
28+
System.out.println(", Age : " + record.getCity());
29+
}
30+
31+
32+
}
33+
34+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /