Vikyath Ram

Vikyath Ram

96 Articles Published

Articles by Vikyath Ram

Page 8 of 10

How to move the ResultSet cursor to the next row in JDBC?

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 1K+ Views

Whenever we execute SQL statements using the executeQuery() method, it returns a ResultSet object which holds the tabular data returned by the SELECT queries(in general).The ResultSet object contains a cursor/pointer which points to the current row. Initially this cursor is positioned before first row (default position).You can move the cursor of the ResultSet object to the next row from the current position, using the next() method of the ResultSet interface.rs.next()This method returns a boolean value specifying whether the ResultSet object contains more rows.If there are no rows next to its current position this method returns false, else it returns true.Let us create ...

Read More

How to get the list of all databases using JDBC?

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 3K+ Views

You can get the list of databases in MySQL using the SHOW DATABASES query.show databases;Following JDBC program retrieves the list of databases by executing the show databases query.Exampleimport java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; public class ShowDatabasesExample {    public static void main(String args[]) throws Exception {       //Registering the Driver       DriverManager.registerDriver(new com.mysql.jdbc.Driver());       //Getting the connection       String mysqlUrl = "jdbc:mysql://localhost/mydatabase";       Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");       System.out.println("Connection established......");       //Creating a Statement object       Statement stmt = con.createStatement(); ...

Read More

How to get column count in a ResultSet in JDBC?

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 6K+ Views

You can get the column count in a table using the getColumnCount() method of the ResultSetMetaData interface. On invoking, this method returns an integer representing the number of columns in the table in the current ResultSet object.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type int column_count = rsmd.getColumnCount();Let us create a table with name employee_data in MySQL database using CREATE statement as shown below −CREATE TABLE employee_data(    id INT,    Name VARCHAR(255),    DOB date,    Location VARCHAR(40) );Following JDBC program establishes connection with the database, retrieves the ResultSetMetaData object of the employee_data table, and prints the number of columns in it.Exampleimport ...

Read More

How to remove a record from an existing table in oracle database using JDBC API?

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 655 Views

You can remove a particular record from a table in a database using the DELETE query.SyntaxDELETE FROM table_name WHERE [condition];To delete a record from a table 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 to 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 object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the executeUpdate() method of the ...

Read More

How to count rows – count (*) and Java

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 10K+ Views

The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Let us create a table with name cricketers_data in MySQL database using CREATE statement as shown below −CREATE TABLE cricketers_data(    First_Name VARCHAR(255),    Last_Name VARCHAR(255),    Date_Of_Birth date,    Place_Of_Birth VARCHAR(255),    Country VARCHAR(255), );Now, we will insert 5 records in cricketers_data table using INSERT statements −insert into cricketers_data values('Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into cricketers_data values('Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into cricketers_data values('Kumara', 'Sangakkara', DATE('1977-10-27'), 'Matale', 'Srilanka'); insert into cricketers_data values('Virat', 'Kohli', DATE('1988-11-05'), 'Delhi', ...

Read More

Bit-Map Protocol

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 4K+ Views

Bit-map protocol is a collision free protocol that operates in the Medium Access Control (MAC) layer of the OSI model. It resolves any possibility of collisions while multiple stations are contending for acquiring a shared channel for transmission.In this protocol, if a station wishes to transmit, it broadcasts itself before the actual transmission. This is an example of Reservation Protocol.Working PrincipleIn this protocol, the contention period is divided into N slots, where N is the total number of stations sharing the channel. If a station has a frame to send, it sets the corresponding bit in the slot.Suppose that there ...

Read More

Token Passing in Bit-Map Protocol

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 2K+ Views

Bit-map protocol is a collision free protocol that operates in the Medium Access Control (MAC) layer of the OSI model. It resolves any possibility of collisions while multiple stations are contending for acquiring a shared channel for transmission. In this protocol, if a station wishes to transmit, it broadcasts itself before the actual transmission. Every station gets its turn for transmission in a predefined order. A method to accomplish this is to use the method of token passing.Token Passing MechanismA token is a small message that circulates among the stations of a computer network providing permission to the stations for ...

Read More

Package extension utility in Python

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 808 Views

When you want to add to the module search path for a specific package and work with resources included in a package, you need to use pkgutil module from Python library. It includes functions for changing the import rules for Python packages. It is also possible to load non-code resources from files distributed within a package.extend_path(path, name)Extend the search path for the modules which comprise a package. Intended use is to place the following code in a package’s __init__.pyimport pkgutil __path__ = pkgutil.extend_path(__path__, __name__)extend_path() scans sys.path for directories that include a subdirectory named for the package given as the second ...

Read More

Java DatabaseMetaData getDatabaseProductVersion() method with example

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 392 Views

The getDatabaseProductVersion() method of the DatabaseMetaData interface returns the version number of the underlying database in String format.To get the version of the underlying database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the getMetaData() method of the Connection ...

Read More

Java DatabaseMetaData getDatabaseProductName() method with example

Vikyath Ram
Vikyath Ram
Updated on 30-Jul-2019 1K+ Views

The getDatabaseProductName() method of the DatabaseMetaData interface returns the name of the underlying database in String format.To know the name of the underlying database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData object with respect to the current connection using the getMetaData() method of the Connection interface.Finally ...

Read More
Showing 71–80 of 96 articles
« Prev 1 6 7 8 9 10 Next »
Advertisements