Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package database;
- import java.sql.*;
- import java.util.ArrayList;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import org.apache.commons.fileupload.FileItem;
- import bean.CreditCard;
- public class DAO {
- Connection con;
- public static String url = "jdbc:mysql://localhost/it3191db?autoReconnect=true&relaxAutoCommit=true";
- public static String dbdriver = "com.mysql.jdbc.Driver";
- public static String username = "root";
- public static String password = "";
- public DAO() throws Exception {
- try {
- Class.forName(dbdriver);
- con = DriverManager.getConnection(url, username, password);// Getting
- // connection
- // to
- // database
- con.setAutoCommit(true);
- } catch (Exception ex) {
- System.out.println("Exception in DBAO " + ex);
- throw new Exception("Couldn't open connection to database: "
- + ex.getMessage());
- }
- }
- public int createCreditCard(String cardNo){
- int status = 0;
- //SQL statement
- String sql = "INSERT INTO it3191db.creditcard (cardNo) VALUES (?)";
- try {
- // Use the connection to create a PreparedStatement object
- PreparedStatement ps = con.prepareStatement(sql);
- ps.setString(1, cardNo);
- status = ps.executeUpdate();
- con.commit();
- con.close();
- } catch (Exception e) {
- System.out.println("SQL Error= " + e.getMessage());
- }
- return status;
- }
- }
Add Comment
Please, Sign In to add comment