final exam Code Flashcards
Change the order
ORDER BY <field> DESC (default is ascending)</field>
counting
SELECT pub_id, COUNT( * )
FROM titles
GROUP BY pub_id
HAVING COUNT( * ) > 5;
Insert Statement
INSERT INTO <table>
VALUES (v1, v2, …);
INSERT INTO <table>(field1, field2,…)
VALUES (v1, v2, …);
Update Statement
UPDATE <table name>
SET <field> = <value>
WHERE <logical></logical></value></field>
Delete Statement
DELETE FROM <table name>
WHERE <logical></logical>
Inner join
From <table> AS <letter> INNER JOIN <table2> as <letter2> ON <use></use></letter2></table2></letter>
SELECT Name, Language
FROM Country AS c INNER JOIN CountryLanguage AS cl ON c.Code = cl.CountryCode
pom file
<dependencies>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.4.0</version>
</dependency>
</dependencies>
JDBC imports and package
package edu.psu.bd.cs.akv5335.<name>;
import java.sql.*;
import java.util.Scanner;</name>
creating a connection code
- create a connection
Connection connection;
Scanner scanner = new Scanner(System.in); - try statement (driver manager, prepared statement, result set, execute query, close connections)
try
{
connection = DriverManager.getConnection(“jdbc:sqlite:\C…”);
PreparedStatement statement = connection.prepareStatement(“write query, use ? for the thing we don’t have”);
ResultSet set;
do
{
get what you need from user
statement.set<user>(1,varName)
set = statement.executeQuery();</user>
//to print out a certain part of the result, do set.getString(“what you want”);
//after do-while
set.close();
connection.close();
- catch statement
catch(SQLException e)
{
e.printStackTrace();
}
web application code
@RestController
public class className
{
@GetMapping(path =”/classNameObject”)
public className methodName(@RequestParam(name = “word”) String word)