Create a Table in JavaDB Using JDBC

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

213 Views

You can create a table in JavaDB database using the CREATE TABLE statement.SyntaxCREATE TABLE table_name (    column_name1 column_data_type1 constraint (optional),    column_name2 column_data_type2 constraint (optional),    column_name3 column_data_type3 constraint (optional) );To create a table in JavaDB using JDBC API you need to −Register the driver − The forName() method of the class, Class accepts a String value representing a class name loads it in to the memory, which automatically registers it. Register the driver using this method.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) ... Read More

C Program for Difference Between Sums of Odd and Even Digits

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

610 Views

Suppose we have one long integer. We have to find if the differences between the sum of the odd position digits, and the sum of the even position digits are 0 or not. The positions are start from 0 (left most).For example, suppose a number is 156486. The odd position sum is (5 + 4 + 6) = 15, and even position sum is (1 + 6 + 8) = 15, so they are same.To solve this problem, we can use two different ways. The first way is traversing form start to end and get the sum by alternating the ... Read More

Nested Functions in C

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

5K+ Views

In some applications, we have seen that some functions are declared inside another function. This is sometimes known as nested function, but actually this is not the nested function. This is called the lexical scoping. Lexical scoping is not valid in C because the compiler is unable to reach correct memory location of inner function.Nested function definitions cannot access local variables of surrounding blocks. They can access only global variables. In C there are two nested scopes the local and the global. So nested function has some limited use. If we want to create nested function like below, it will ... Read More

Perform Multiplication in SELECT Depending on Column Value in MySQL

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

742 Views

You can use CASE statement for this. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value1 int,    Value2 int    ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value1, Value2) values(10, 5); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable(Value1, Value2) values(20, 0); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Value1, Value2) values(40, 10); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable(Value1, Value2) ... Read More

Use 'this' Keyword in Static Context in Java

Maruthi Krishna
Updated on 30-Jul-2019 22:30:26

1K+ Views

A static method or, block belongs to the class and these will be loaded into the memory along with the class. You can invoke static methods without creating an object. (using the class name as reference).Whereas "this" in Java acts as a reference to the current object. But static contexts(methods and blocks) doesn't have any instance they belong to the class.In a simple sense, to use “this” the method should be invoked by an object, which is not always necessary with static methods.Therefore, you cannot use this keyword from a static method.ExampleIn the following Java program, the class ThisExample contains a private ... Read More

Display PDF Document in Android WebView

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

2K+ Views

This example demonstrate about How to lock the Android device programmatically.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml     Step 3 − Add the following code to src/MainActivitypackage app.tutorialspoint.com.sample ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import android.webkit.WebView ; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate (Bundle savedInstanceState) {       super .onCreate(savedInstanceState) ;       setContentView(R.layout. activity_main ) ;    } ... Read More

Search for String or Number in a Field with MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

961 Views

You can use $in operator for this. Let us first create a collection with documents −> db.searchForStringOrNumberDemo.insertOne(    {       "_id": new ObjectId(),       "StudentName": "Larry",       "StudentDetails": {          "StudentMarks": {             "StudentMongoDBMarks": [44]          }       }    } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce2407c36e8b255a5eee944") } > db.searchForStringOrNumberDemo.insertOne( { "_id": new ObjectId(), "StudentName": "Larry", "StudentDetails": { "StudentMarks": { "StudentMongoDBMarks": ["44"] } } } ); {    "acknowledged" : true,    "insertedId" : ObjectId("5ce240f036e8b255a5eee945") }Following is ... Read More

Drop a Table from JavaDB Using JDBC

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

172 Views

You can create a table in a database using the CREATE TABLE query.SyntaxCREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ..... columnN datatype, PRIMARY KEY( one or more columns ) );To create a table in a database using JDBC API you need to −Register the driver − Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection − Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement − Create a Statement ... Read More

Efficiently Print All Prime Factors of a Given Number in C

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

709 Views

In this section, we will see how we can get all the prime factors of a number in an efficient way. There is a number say n = 1092, we have to get all prime factors of this. The prime factors of 1092 are 2, 2, 3, 7, 13. To solve this problem, we have to follow this rule −When the number is divisible by 2, then print 2, and divide the number by 2 repeatedly.Now the number must be odd. Now starting from 3 to square root of the number, if the number is divisible by current value, then ... Read More

Get Font Metrics in Java Swing

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

560 Views

To get the font metrics, use the FontMetrics class:Graphics2D graphics = (Graphics2D) gp.create(); String str = getWidth() + "(Width) x (Height)" + getHeight(); FontMetrics m = graphics.getFontMetrics();Now to display it:int xValue = (getWidth() - m.stringWidth(str)) / 2; int yValue = ((getHeight() - m.getHeight()) / 2) + m.getAscent(); graphics.drawString(str, xValue, yValue);The following is an example to get the font metrics in Java Swing:Exampleimport java.awt.BorderLayout; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame("Font Metrics");       ... Read More

Advertisements