BTW, You might want to check out ChatGPT for help with all this. it’s pretty good at writing simple code like SQl queries or front ends.
For example, I just asked it this:
“Can you write a java program that connects to a mySQL instance called “penbase”, and creates a table with rows that include the pen name, color, age, price, and pen type from an enumerated list containing “Fountain”, “ballpoint”, and “pencil”. I want the table created if it does 't already exist.”
ChatGPT responded with, “Sure! Here you go” Then gave me this code:
import java.sql.*;
public class CreateTable {
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/penbase";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
// Register JDBC driver
Class.forName(JDBC_DRIVER);
// Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
// Execute a query to create table
System.out.println("Creating table in given database...");
stmt = conn.createStatement();
String sql = "CREATE TABLE IF NOT EXISTS Pens " +
"(name VARCHAR(255), " +
" color VARCHAR(255), " +
" age INTEGER, " +
" price DECIMAL, " +
" type ENUM('Fountain', 'ballpoint', 'pencil'))";
stmt.executeUpdate(sql);
System.out.println("Created table in given database...");
// Clean-up environment
stmt.close();
conn.close();
} catch(SQLException se) {
// Handle errors for JDBC
se.printStackTrace();
} catch(Exception e) {
// Handle errors for Class.forName
e.printStackTrace();
} finally {
// finally block used to close resources
try {
if(stmt!=null) stmt.close();
} catch(SQLException se2) {
} // nothing we can do
try {
if(conn!=null) conn.close();
} catch(SQLException se) {
se.printStackTrace();
} // end finally try
} // end try
System.out.println("Goodbye!");
}
}
I could then ask it to make another froht end for end users that allows them to query the database by whatever, add pens, delete pens, view pens, etc. It will also create an app front end using React or any other web front end tool you like, or build the code for a standalone app. It’ll probably write the install scripts for you too.
Oh, I forgot you wanted an image field. Since ChatGPT remembers the context of our conversation, I just asked it, “Oh, I forgot I need an image field for storing a picture of the pen. can you add that?” And it did.
import java.sql.*;
public class CreateTable {
static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/penbase";
static final String USER = "username";
static final String PASS = "password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
// Register JDBC driver
Class.forName(JDBC_DRIVER);
// Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL, USER, PASS);
// Execute a query to create table
System.out.println("Creating table in given database...");
stmt = conn.createStatement();
String sql = "CREATE TABLE IF NOT EXISTS Pens " +
"(name VARCHAR(255), " +
" color VARCHAR(255), " +
" age INTEGER, " +
" price DECIMAL, " +
" type ENUM('Fountain', 'ballpoint', 'pencil'), " +
" image BLOB)";
stmt.executeUpdate(sql);
System.out.println("Created table in given database...");
// Clean-up environment
stmt.close();
conn.close();
} catch(SQLException se) {
// Handle errors for JDBC
se.printStackTrace();
} catch(Exception e) {
// Handle errors for Class.forName
e.printStackTrace();
} finally {
// finally block used to close resources
try {
if(stmt!=null) stmt.close();
} catch(SQLException se2) {
} // nothing we can do
try {
if(conn!=null) conn.close();
} catch(SQLException se) {
se.printStackTrace();
} // end finally try
} // end try
System.out.println("Goodbye!");
}
}
You could try asking it for front ends, or even ask it for advice on how to build an app you can distribute.