Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Jdbc dbConn = new Jdbc();
- Connection con = dbConn.connect();
- String insert_member = "INSERT INTO Members (id, name, address, dob, "
- + "dor, status, balance)" + " VALUES (?, ?, ?, ?, ?, ?, ?)";
- //String c = con.toString();
- //con = null for some reason
- pstmt = con.prepareStatement(insert_member);
- pstmt.setString(1, "coo");
- pstmt.setString(2, "aa");
- pstmt.setString(3, "26 road");
- pstmt.setDate(4, new java.sql.Date(new Date().getTime()));
- pstmt.setDate(5, new java.sql.Date(new Date().getTime()));
- pstmt.setString(6, "APPLIED");
- pstmt.setFloat(7, 10);
- pstmt.execute();
- public Jdbc() {
- String db = "xyz_assoc";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- connection = DriverManager.getConnection
- ("jdbc:mysql://localhost:3306/"+db.trim(), "root", "");
- }
- catch(ClassNotFoundException cfe){
- }
- //SQL exception
- catch (SQLException ex) {
- Logger.getLogger(Jdbc.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- //open connection to database
- public Connection connect(){
- return connection;
- }
- //execute mysql queryS
- public ResultSet executeQuery(String sql_query) throws SQLException {
- statement = null;
- statement = connection.createStatement();
- rs = statement.executeQuery(sql_query);
- return rs;
- }
- //close connection to database
- //destroy any remaining objects
- public void close() throws SQLException{
- statement.close();
- rs.close();
- connection.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement