Write JDBC Program to Extract Data from Multiple Databases

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

1K+ Views

To connect with a data base, you need toRegister the DriverSelect the required database register the Driver class of the particular database using the registerDriver() method of the DriverManager class or, the forName() method of the class named Class.DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get connectionCreate a connection object by passing the URL of the database, username and password of a user in the database (in string format) as parameters to the getConnection() method of the DriverManager class.Connection mysqlCon = DriverManager.getConnection(mysqlUrl, "root", "password");And, to extract data you need to execute the select query as:ResultSet rs = stmt.executeQuery("Select * from Employee");To print the contents of the ... Read More

Remove Java Variable from Current Scope in JSP

Samual Sam
Updated on 30-Jul-2019 22:30:25

520 Views

The tag removes a variable from either a specified scope or the first scope where the variable is found (if no scope is specified). This action is not particularly helpful, but it can aid in ensuring that a JSP cleans up any scoped resources it is responsible for.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultvarName of the variable to removeYesNonescopeScope of the variable to removeNoAll scopesExample           Tag Example           Before Remove Value: After Remove Value: The above code will generate the following result −Before Remove Value: 4000 After Remove Value:

Period ofMonths Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

241 Views

The Period can be obtained with the given number of months using the ofMonths() method in the Period class in Java. This method requires a single parameter i.e. the number of months and it returns the Period object with the given number of months.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { int months = 11; Period p = Period.ofMonths(months); System.out.println("The Period is: " + p); ... Read More

ArrayBlockingQueue Peek Method in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:25

175 Views

The peek() method of the ArrayBlockingQueue class returns the head of this queue or null if this queue is empty.The syntax is as follows.public E peek()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement peek() method of Java ArrayBlockingQueue class.Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(200);       q.add(310);       q.add(400);       q.add(450);       q.add(500);       q.add(550);       ... Read More

Check If a Field Contains a String in MongoDB

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

You can use $regex operator to check if a field contains a string in MongoDB. The syntax is as follows −db.yourCollectionName.findOne({"yourFieldName":{$regex:".*yourValue.*"}});To understand the above concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.checkFieldContainsStringDemo.insertOne({"Id":1, "Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77d762fc4e719b197a12ed") } > db.checkFieldContainsStringDemo.insertOne({"Id":2, "Name":"Johnson"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77d76bfc4e719b197a12ee") } > db.checkFieldContainsStringDemo.insertOne({"Id":3, "Name":"Carol"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77d774fc4e719b197a12ef") } > db.checkFieldContainsStringDemo.insertOne({"Id":4, "Name":"Mike"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c77d77cfc4e719b197a12f0") } > db.checkFieldContainsStringDemo.insertOne({"Id":5, "Name":"Sam"}); ... Read More

Add to Existing Value in MySQL Column Using CONCAT Function

Chandu yadav
Updated on 30-Jul-2019 22:30:25

921 Views

To understand the concept, let us first create a demo table.mysql> create table addToExistingValueDemo    -> (    -> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Instructor_Name varchar(30),    -> Instructor_TechnicalSubject text    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('John', 'C, C++'); Query OK, 1 row affected (0.15 sec) mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('Carol', 'Java, Python'); Query OK, 1 row affected (0.18 sec) mysql> insert into addToExistingValueDemo(Instructor_Name, Instructor_TechnicalSubject) values('Bob', 'MySQL, SQL Server'); Query OK, 1 row ... Read More

Update MongoDB Collection Using toLower

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

743 Views

There is a $toLower operator in MongoDB to be used as part of aggregate framework. But, we can also use the for loop to iterate over the specific field and update one by one.Let us first create a collection with documents> db.toLowerDemo.insertOne({"StudentId":101, "StudentName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1b4515e86fd1496b38bf") } > db.toLowerDemo.insertOne({"StudentId":102, "StudentName":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1b4b15e86fd1496b38c0") } > db.toLowerDemo.insertOne({"StudentId":103, "StudentName":"CHris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1b5115e86fd1496b38c1") } > db.toLowerDemo.insertOne({"StudentId":104, "StudentName":"ROBERT"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1b5a15e86fd1496b38c2") }Following is the query to display all documents from ... Read More

Append All Elements of Collection to ArrayList in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

219 Views

Let us first create an ArrayList −ArrayListarr = new ArrayList(); arr.add("50"); arr.add("100"); arr.add("150"); arr.add("200"); arr.add("250"); arr.add("300");Now, let’s say we have another Collection as Vector −Vectorvector = new Vector(); vector.add("500"); vector.add("700"); vector.add("800"); vector.add("1000"); Append all the elements from the Vector to ArrayList: arr.addAll(vector);Example Live Demoimport java.util.ArrayList; import java.util.Vector; public class Demo {    public static void main(String[] args) {       ArrayListarr = new ArrayList();       arr.add("50");       arr.add("100");       arr.add("150");       arr.add("200");       arr.add("250");       arr.add("300");       Vectorvector = new Vector();       vector.add("500");   ... Read More

Order Randomly in MySQL with a Random Value Column

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

283 Views

Let us first create a table. After that we will create a new random value column and order the record randomly:mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentName varchar(20) ); Query OK, 0 rows affected (0.57 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(StudentName) values('Larry'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName) values('Sam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName) values('Mike'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable(StudentName) values('Carol'); Query OK, 1 ... Read More

Meaning of const Last in a Function Declaration of a C++ Class

Anvi Jain
Updated on 30-Jul-2019 22:30:25

862 Views

Sometimes we can find the keyword ‘const’ present at the last of function declaration. So what does it mean?Using this one function can be made as constant. The idea of constant function is that, the function cannot be modified from the objects, where they are called. It is recommended to use the constant functions in our program.Let us see one example of constant function.Example#include using namespace std; class MyClass {    int value;    public:       MyClass(int val = 0) {          value = val;       }       int getVal() const ... Read More

Advertisements