Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String newq="select *from account";
- ResultSet rs = s.executeQuery(newq);
- package exotiqueDatabaseConnection;
- import java.sql.*;
- import java.io.PrintWriter;
- import java.io.Serializable;
- public class ConnectDatabase implements Serializable {
- Statement stmt;
- Connection conn;
- ResultSet rs;
- String username;
- String password;
- String driver;
- String url;
- public ConnectDatabase()
- {
- try{
- username="root";
- password="does001";
- driver="com.mysql.jdbc.Driver";
- Class.forName(driver);
- url="jdbc:mysql://localhost/exotique";
- conn=DriverManager.getConnection(url, username, password);
- stmt=conn.createStatement();
- }
- catch(ClassNotFoundException cnfe)
- {
- }
- catch (SQLException sq)
- {
- }
- }
- public void populateUsers(String usernameIn, String emailIn, String passwordIn)
- {
- try{
- /* username="root";
- password="does001";
- driver="com.mysql.jdbc.Driver";
- try {
- Class.forName(driver);
- } catch (ClassNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- url="jdbc:mysql://localhost/exotique";
- conn=DriverManager.getConnection(url, username, password);
- stmt=conn.createStatement();*/
- CallableStatement cs=conn.prepareCall("{call populateusers(?,?,?)}");
- cs.setString(1, usernameIn);
- cs.setString(2, emailIn);
- cs.setString(3, passwordIn);
- cs.execute();
- }
- catch(SQLException sq)
- {
- System.out.print(sq.getMessage());
- }
- catch(Exception ex)
- {
- System.out.print(ex.getMessage());
- }
- finally
- {
- close(conn);
- close(rs);
- close(stmt);
- }
- }
- @SuppressWarnings("finally")
- public ResultSet showAllBooks()
- {
- try{
- CallableStatement cs=conn.prepareCall("{call getAllBooks}");
- cs.execute();
- rs=cs.getResultSet();
- }
- catch(SQLException sq)
- {
- System.out.print(sq.getMessage());
- }
- catch(Exception ex)
- {
- System.out.print(ex.getMessage());
- }
- finally
- {
- close(conn);
- close(rs);
- close(stmt);
- return rs;
- }
- }
- public void close(Statement stmt)
- {
- if(stmt!=null)
- {
- try{
- stmt.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public void close(Connection conn)
- {
- if(conn!=null)
- {
- try
- {
- conn.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- public void close(ResultSet rs)
- {
- if(rs!=null)
- {
- try
- {
- rs.close();
- }
- catch(SQLException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment