zapisywanie plików do bazdy danych

0

Cześć,
mam problem z zapisaniem plików (txt) do bazy danych MySQL. Prośba o pomoc.

Connection conn = null;
        Statement stm = null;
        String sql = "INSERT INTO PRICES(NAME,FIlE) VALUES(?,?)";
        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection("mysql://localhost/price.db");
            stm = conn.createStatement();

            String command = "DROP TABLE PRICES";
            try {
                stm.executeUpdate(command);
            } catch (Exception ex) {

            }
            command = "CREATE TABLE PRICES("
                    + "name TEXT,"
                    + "file BLOB"
                    + ");";
            stm.executeUpdate(command);

            String filePath = "C:\\work\\ProjektyNetbeans\\SidGroup\\plik2.txt";
            File file = new File(filePath);
            try (
                    FileInputStream inputStream = new FileInputStream(file);
                    PreparedStatement stmt = conn.prepareStatement(sql);) {

                stmt.setString(1, "Mike");
                stmt.setBinaryStream(2, inputStream, file.length());
                stmt.executeUpdate();
                System.out.println("File saved successfully.");

            } catch (SQLException ex) {
                Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
            }
        } catch (SQLException ex) {
            Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(DBInitialization.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

otrzymuje w konsoli następujące komunikaty:

SEVERE: null
java.sql.SQLException: No suitable driver found for mysql://localhost/price.db

0

Musisz nauczyć się angielskiego w stopniu umożliwiającym czytanie raportów na stackoverflow. Potem wystarczy wkleić komunikat do tzw. wyszukiwarki internetowej. Znajdziesz ją pod adresem google.pl.

Ale wydaje mi się, że nawet jakby było po chińsku, to bym zrozumiał: https://stackoverflow.com/questions/42643887/cant-connect-to-mysql-database-no-suitable-driver-found

0

Widzę ze Twoją główną cechą jest wymądrzanie się.
dzięki za link.

1 użytkowników online, w tym zalogowanych: 0, gości: 1