Java JDBC
Required downloads before start to work with java JDBC.
- Java any latest version (set classpath)
- any Database here using MySql
- respective JDBC driver for Database (.jar file)
- Code-Editor (Eclipse)
set path for JDBC driver
> Steps to Connect with Database
Statement : normal query( SELECT,INSERT,UPDATE,DELETE)
PreparedStatement : Dynamic query
CallableStatement : execute function or method in database
column name as parameter
> Implementation by creating table (Normal Statement query) :
here with help of PreparedStatement interface we will call method prepareStatement().
then executeupdate() without any parameter
> Inserting Images(less size i.e less then 65kb) in database:
here we have taken image as FileInputStream Object as we know it takes input in form of bytes.
and here we have used image name since both program and image were in same folder if not give full path.
here setBinaryStream() parameters are :
- 1 for firstposition
- fis for value to insert at first position
- fis.available() here is used for bytes available in stream
> for storing images of large size we will have to change type to longblob:
so here we have called connection method from above to create connection.
Here swing component of java which provide graphical user interface so here we by JFileChooser which is from Swing we can select file from system in GUI form.
jfc.showOpenDialog(null): here null is for centering the GUI window.
Similarly JOptionPane is GUI for showing success msg to user.
---------------------------------------------------------------------------------------------------------------------
Comments
Post a Comment