Note that there are some explanatory texts on larger screens.

plurals
  1. POhow do i add a scanner so i can insert the values which are then saved on to mysql
    primarykey
    data
    text
    <p><strong>basically I need to add another scanner input which after login in to I can add an id and name etc to my database so I don't have to use the set one in the program. the database gets updated when I just change the set insert values so the connection is fine I just don't know how a user would insert the values without the code which would then update the database after entering.</strong></p> <pre><code>import java.sql.*; import java.util.Scanner; public class JDBCInsertValues{ static final String DRIVER = "com.mysql.jdbc.Driver"; // JDBC driver static final String DATABASE = "test"; // the database name static final String HOST = "10.1.63.200"; // the database host IP // the full URL: static final String DATABASE_URL = "jdbc:mysql://" + HOST + "/" + DATABASE; public static void main(String[] args) { System.out.println("Inserting values into MySQL database table..."); Connection con = null; try{ Class.forName(DRIVER); Scanner keyboard = new Scanner(System.in); System.out.print("Login: "); String login = keyboard.next(); System.out.print("Password: "); String password = keyboard.next(); con = DriverManager.getConnection(DATABASE_URL,login,password); try{ Statement st = con.createStatement(); String sql = "INSERT INTO Authors VALUES(67,\"Mark\",\"Cooper\")"; System.out.println(sql); int val = st.executeUpdate(sql); System.out.println(val + " rows inserted."); } catch (SQLException s){ System.out.println("SQL statement is not executed!"); s.printStackTrace(); } } catch (Exception e){ e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload