Posts

Showing posts with the label MySQL

SQL Syntaxes

Select data from a table To select all(*) the data from a table  SELECT * FROM TABLE_NAME; To select specific columns of a table SELECT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; ; DISTINCT - To select distinct(different) values SELECT DISTINCT COLUMN_1, COLUMN_2,..., COLUMN_n FROM TABLE_NAME; To list the number of distinct rows SELECT COUNT(DISTINCT COLUMN_NAME) FROM TABLE_NAME; or SELECT COUNT(*) AS COLUMN_NAME_IDENTIFIER FROM (SELECT DISTINCT COLUMN_NAME FROM TABLE_NAME); To give a condition to the select statement SELECT COLUMN_1, COLUMN_2,...,COLUMN_n FROM TABLE_NAME  WHERE condition When using the WHERE condition, 1. if it's an integer COLUMN_NAME = INT_VALUE 2. if it's a string (single quotation is required) COLUMN_NAME = 'STRING_VALUE' 3. if it's a date (single quotation is required and the format must be YYYY-MM-DD) COLUMN_NAME = 'YEAR-MONTH-DATE' Using AND syntax with WHERE con...

Getting started with MySQL using wamp server

After installing the wamp server on your computer follow the below steps. Step 1 : Run the command prompt.  Step 2 : Copy the path of the bin folder of the wamp server. usually it is, C:\wamp64\bin\mysql\mysql5.7.19\bin Step 3 : Go back to the command prompt and change the directory to the path you copied C:\Users\admin>cd C:\wamp64\bin\mysql\mysql5.7.19\bin Step 4 : Then type the command "mysql -u root -p", then press enter. C:\wamp64\bin\mysql\mysql5.7.19\bin>mysql -u root -p Step 5 : Then it will request the password, just enter because there isn't a password. Enter password: Step 6 : If you have successfully connected following message will be prompted. Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.7.19 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and...

Java + MySql

How to input data into a MySQL Data Base table using java Example Package = Test2 Class = DB Data Base = studentinfo Table Name = bank package Test2; import java.sql.*; class DB { public static void main(String args[]) { try { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/studentinfo", "root", ""); String sql = "insert into bank " + " (Account_No, Customer_Name, Intrest_Rate, Current_Balance)" + " values (?, ?, ?, ?)"; PreparedStatement stmt=con.prepareStatement(sql); stmt.setString(1, "123456"); stmt.setString(2, "Pamitha"); stmt.setInt(3, 10); stmt.setInt(4, 1000); stmt.executeUpdate(); c...