package booksshop;

import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.DriverManager;
import java.sql.*;
import java.util.*;

public class Books {

    Connection con;
    Statement st;

    String url;
    String serverName;
    String portNumber;
    String databaseName;
    String userName;
    String password;
    String sql;

    public Books() {
        con = this.getConnection();
        try {
            st = con.createStatement();
        } catch (SQLException ex) {
        }
    }

    public void addbook(String title, String author, String publisher, int pages, float price, String isbn) {


        sql = "insert into acebooks values ('" + title + "', '" + author + "', '" + publisher + "', " + pages + "," + price + ", '" + isbn + "')";

        try {
            st.executeUpdate(sql);
        } catch (SQLException ex) {System.out.println("eee"+ex);
        }
    }

    private String getConnectionUrl()
    {
        url = "jdbc:microsoft:sqlserver://";
        serverName = "127.0.0.1";
        portNumber = "1433";
        databaseName = "master";
        userName = "sa";
        password = "";

        return url + serverName + ":" + portNumber + ";databaseName=" + databaseName + ";";
    }

    private java.sql.Connection getConnection()
    {
        try
        {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            con = java.sql.DriverManager.getConnection("jdbc:odbc:uuu","","");

            if(con != null)
                System.out.println("Á¬½Ó³É¹¦£¡");

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        return con;
    }
}
