Skip to content

Commit

Permalink
JDBC added
Browse files Browse the repository at this point in the history
  • Loading branch information
tracksdata committed Sep 4, 2017
1 parent e61318e commit 61d68e2
Show file tree
Hide file tree
Showing 37 changed files with 896 additions and 6 deletions.
7 changes: 5 additions & 2 deletions Database/PL SQL Scripts/p1.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
CREATE OR REPLACE PROCEDURE p1(no in number)
CREATE OR REPLACE PROCEDURE p11
AS
BEGIN
dbms_output.put_line('Square of '||no|| ' is '||no*no);

update product set product_name='Monitor' where product_id='P001';
commit;

END;
8 changes: 8 additions & 0 deletions Database/PL SQL Scripts/p111.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE OR REPLACE PROCEDURE p11(pid in varchar2(10))
AS
BEGIN

update product set product_name='New Value' where product_id=pid;
commit;

END;
1 change: 1 addition & 0 deletions JDBC/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.metadata/
/.recommenders/
Binary file modified JDBC/JDBC-Test/bin/com/CreteTableDemo.class
Binary file not shown.
Binary file added JDBC/JDBC-Test/bin/com/OracleDB.class
Binary file not shown.
13 changes: 9 additions & 4 deletions JDBC/JDBC-Test/src/com/CreteTableDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

public class CreteTableDemo {
Expand All @@ -13,22 +14,26 @@ public static void main(String[] args) {
try {

Class.forName("oracle.jdbc.driver.OracleDriver");
// System.out.println("-- Driver class loaded");
System.out.println("-- Driver class loaded");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:mphasis", "scott", "tiger");
// System.out.println("-- Connection Established with "+con);

// CReate a statement interface

Statement stmt = con.createStatement();

String qry = "create table bank(cust_id number primary key,cust_name varchar2(20))";
//String qry = "create table bank(cust_id number primary key,cust_name varchar2(20))";

stmt.executeUpdate(qry);
//stmt.executeUpdate(qry);

System.out.println("--- Query Processed..");

} catch (Exception e) {
} catch (SQLException e) {
System.out.println("--- Failed due to " + e);
} catch (ClassNotFoundException cnf) {

} catch (Exception ee) {

}

}
Expand Down
40 changes: 40 additions & 0 deletions JDBC/JDBC-Test/src/com/OracleDB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import oracle.jdbc.driver.OracleDriver;

public class OracleDB {

public static void main(String[] args) {

// 1. Load Driver class

Connection con = null;


try {


Class.forName("oracle.jdbc.driver.OracleDriver");
// System.out.println("-- Driver class loded");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:mphasis", "scott", "tiger");
// System.out.println("-- Connection Established with "+con);

} catch (Exception e) {
System.out.println("--- Failed due to " + e);
}finally {
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

}
7 changes: 7 additions & 0 deletions JDBC/Jdbc-App-1/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/JDBC-Driver"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions JDBC/Jdbc-App-1/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Jdbc-App-1</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions JDBC/Jdbc-App-1/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
Binary file added JDBC/Jdbc-App-1/bin/com/CallableStatementDemo.class
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/FindProduct.class
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/ListProducts.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/SaveProduct_Statement.class
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/TransactionTest.class
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/product/dao/DbUtils.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added JDBC/Jdbc-App-1/bin/com/product/model/Product.class
Binary file not shown.
18 changes: 18 additions & 0 deletions JDBC/Jdbc-App-1/src/com/CallableStatementDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com;

import com.product.dao.StoredProcedures;

public class CallableStatementDemo {

public static void main(String[] args) {

StoredProcedures sp=new StoredProcedures();
sp.demo7();

System.out.println("--- Done ");



}

}
23 changes: 23 additions & 0 deletions JDBC/Jdbc-App-1/src/com/FindProduct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com;

import java.util.List;

import com.product.dao.ProductDaoImpl;
import com.product.model.Product;

public class FindProduct {

public static void main(String[] args) {

ProductDaoImpl prodDao = new ProductDaoImpl();

Product p = prodDao.findProduct("P00001");

System.out.println(p.getProdId());
System.out.println(p.getProdName());
System.out.println(p.getPrice());
System.out.println("--------------------");

}

}
32 changes: 32 additions & 0 deletions JDBC/Jdbc-App-1/src/com/ListProducts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com;

import java.util.List;

import com.product.dao.ProductDaoImpl;
import com.product.model.Product;

public class ListProducts {

public static void main(String[] args) {

Product prod=new Product();
prod.setProdId("P007");
prod.setProdName("Mobile");
prod.setPrice(4453);


ProductDaoImpl prodDao=new ProductDaoImpl();
//prodDao.saveProduct_v1(prod);

List<Product> prods= prodDao.listAll();

for(Product p:prods) {
System.out.println(p.getProdId());
System.out.println(p.getProdName());
System.out.println(p.getPrice());
System.out.println("--------------------");
}

}

}
25 changes: 25 additions & 0 deletions JDBC/Jdbc-App-1/src/com/ListProducts_ResultSetTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com;

import java.util.List;

import com.product.dao.ProductDaoImpl;
import com.product.model.Product;

public class ListProducts_ResultSetTypes {

public static void main(String[] args) {

ProductDaoImpl prodDao = new ProductDaoImpl();



Product p = prodDao.findProduct_v2();

System.out.println(p.getProdId());
System.out.println(p.getProdName());
System.out.println(p.getPrice());
System.out.println("--------------------");

}

}
25 changes: 25 additions & 0 deletions JDBC/Jdbc-App-1/src/com/SaveProduct_PreparedStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com;

import java.util.List;

import com.product.dao.ProductDaoImpl;
import com.product.model.Product;

public class SaveProduct_PreparedStatement {

public static void main(String[] args) {

Product prod=new Product();
prod.setProdId("P007");
prod.setProdName("Mobile");
prod.setPrice(4453);


ProductDaoImpl prodDao=new ProductDaoImpl();
prodDao.saveProduct_v1(prod);



}

}
25 changes: 25 additions & 0 deletions JDBC/Jdbc-App-1/src/com/SaveProduct_Statement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com;

import java.util.List;

import com.product.dao.ProductDaoImpl;
import com.product.model.Product;

public class SaveProduct_Statement {

public static void main(String[] args) {

Product prod=new Product();
prod.setProdId("P007");
prod.setProdName("Mobile");
prod.setPrice(4453);


ProductDaoImpl prodDao=new ProductDaoImpl();
prodDao.saveProduct(prod);



}

}
13 changes: 13 additions & 0 deletions JDBC/Jdbc-App-1/src/com/TransactionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com;

import com.product.dao.JdbcTransactions;

public class TransactionTest {

public static void main(String[] args) {

JdbcTransactions jt=new JdbcTransactions();
jt.demo2();
}

}
44 changes: 44 additions & 0 deletions JDBC/Jdbc-App-1/src/com/product/dao/DbUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.product.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbUtils {

private DbUtils() {
// TODO Auto-generated constructor stub
}

private static Connection con = null;

public static Connection getConnection() {

if (con == null) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:mphasis", "scott", "tiger");

} catch (Exception e) {

e.printStackTrace();
}
} // end of if
return con;
}// get connection end


public static void closeConnection() {

if(con!=null)
try {
con.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


} // closeConnection end

} // class end
Loading

0 comments on commit 61d68e2

Please sign in to comment.