Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private java.sql.Connection con = null;
- private PreparedStatement pst = null;
- private ResultSet rs = null;
- private String url = "jdbc:mysql://localhost:8889/deliveryEarn";
- private String user = "root";
- private String password = "root";
- try {
- con = DriverManager.getConnection(url, user, password);
- Statement st = (Statement) con.createStatement();
- st.executeUpdate("INSERT INTO incomeCalc " + "VALUES (3, 75, 6, 25, 18.50)");
- con.close();
- }
- catch (SQLException ex) {
- Logger lgr = Logger.getLogger(deliveryMain.class.getName());
- lgr.log(Level.SEVERE, ex.getMessage(), ex);
- }
- INSERT INTO incomeCalc VALUES (3, 75, 6, 25, 18.50) // error
- // the only way this will work is when you have only 5 columns in
- // your table but in your case you have 7 that is why it wll not work
- INSERT INTO incomeCalc(specify columns here to the values bound to)
- VALUES (3, 75, 6, 25, 18.50)
- INSERT INTO table_name
- VALUES (value1, value2, value3,...)
- INSERT INTO table_name (column1, column2, column3,...)
- VALUES (value1, value2, value3,...)
- "INSERT INTO incomeCalc(ID, TIPS, HOURS, GAS, HOURLY_EARNINGS) " +
- "VALUES (3, 75, 6, 25, 18.50)"
- "INSERT INTO incomeCalc (ID, TIPS, HOURS, GAS, HOURLY_EARNINGS) VALUES (3, 75, 6, 25, 18.50)"
- ps = "INSERT INTO incomeCalc(ID, TIPS, HOURS, GAS, HOURLY_EARNINGS) VALUES (?, ?, ?, ?, ?)"
- ps.setInt(index++, id); //id=3
- ps.setInt(index++, tips); //tips=75
- ps.setInt(index++, hours);//hour=6
- ps.setInt(index++, gas);//gas=25
- ps.setFloat(index++, HOURLY_EARNINGS);
- INSERT INTO TABLE_NAME (COLUMN_NAMES_SEPARATED_BY_COMMA) VALUES (VALUES_SEPARATED_BY_COMMA)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement