View Photo From Db MySql

View Photo From Db MySql

Good Morning Sir,

Please help me, I make a small code but i have a error. I want to make viewer photo from database MySql into my project in netbeans. this is my code :

try {

        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
 Connection con = DriverManager.getConnection("jdbc:odbc:hyt","root","");
 Statement stat = con.createStatement();
 ResultSet res = stat.executeQuery("select * from kar where nik  ='"+jTextField1.getText()+"'");
if (res.next())
{
jTextField1.setText(res.getString("nik"));
jTextField9.setText(res.getString("nm_kary"));
jComboBox6.setSelectedItem(res.getString("jns_klmin"));
jComboBox2.setSelectedItem(res.getString("jabatan"));
jTextField3.setText(res.getString("cab"));
jComboBox7.setSelectedItem(res.getString("pend"));
jTextField20.setText(res.getString("nm_scul"));
jDateChooser2.setDate(res.getDate("tgl_msk"));
eGambar.setText(foto(jTextField1.getText()));

Blob blob2 = res.getBlob("poto");
jLabel24.setIcon(new javax.swing.ImageIcon(blob2.getBytes(1, (int) (blob2.length()))));
// 
jPanel9.setVisible(true);
}
} catch (Exception e) {
    JOptionPane.showMessageDialog(null,"error "+e);
}

i have error : error java.lang.UnsupportedOpertionException

please help me, Thank you, regards, Hendra

View Answers

June 25, 2012 at 12:56 PM

The given code accept the id from the user and display the image, name and address corresponding to the id.

import java.sql.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class RetrieveImageWithData{
    public static void main(String[] args)throws Exception{
        final JFrame f=new JFrame();
        f.setLayout(null);
        final JLabel lab=new JLabel("Enter ID: ");
        final JTextField text=new JTextField(20);
        final JButton b=new JButton("Display");
        final JLabel lab1=new JLabel();
        final JLabel lab2=new JLabel("Name");
        final JTextField text1=new JTextField(20);
        final JLabel lab3=new JLabel("Address");
        final JTextField text2=new JTextField(20);
        b.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
            int id=Integer.parseInt(text.getText());
        lab1.setVisible(true);
        lab2.setVisible(true);
        text1.setVisible(true);
        lab3.setVisible(true);
        text2.setVisible(true);
        try{
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root" );
        Statement st=conn.createStatement();
        ResultSet rs=st.executeQuery("select * from data where id="+id+"");
        byte[] bytes = null;
        if(rs.next()){
            String name=rs.getString("name");
            text1.setText(name);
            String address=rs.getString("address");
            text2.setText(address);  
            bytes = rs.getBytes("image");
            Image image = f.getToolkit().createImage(bytes);
            ImageIcon icon=new ImageIcon(image);
            lab1.setIcon(icon);
        }
        }
        catch(Exception ex){
        System.out.println(ex);
        }
            }
        });
        lab.setBounds(10,10,100,20);
        text.setBounds(150,10,100,20);
        b.setBounds(250,10,100,20);
        lab1.setBounds(150,40,100,70);
        lab2.setBounds(10,120,100,20);
        text1.setBounds(150,120,100,20);

        lab3.setBounds(10,150,100,20);
        text2.setBounds(150,150,100,20);

        lab1.setVisible(false);
        lab2.setVisible(false);
        text1.setVisible(false);
        lab3.setVisible(false);
        text2.setVisible(false);
        f.add(lab);
        f.add(text);
        f.add(b);
        f.add(lab1);
        f.add(lab2);
        f.add(text1);
        f.add(lab3);
        f.add(text2);
        f.setVisible(true);
        f.setSize(350,200);
    }
}

July 3, 2012 at 7:11 AM

Hello,

Thank you for your help. How to function this code, i already used that but cannot view anything. can you help me again. thank you

regards, hendra









Related Tutorials/Questions & Answers:
View Photo From Db MySql
View Photo From Db MySql  Good Morning Sir, Please help me, I make a small code but i have a error. I want to make viewer photo from database MySql into my project in netbeans. this is my code : try
Store image from html img tag into mysql db using java
Store image from html img tag into mysql db using java  Hi. How to get the image displayed in the < img > tag of HTML and store it in the mysql database using java? Thanks in advance
Advertisements
retrieving image from mysql db with standard height and width
retrieving image from mysql db with standard height and width  Hi . Here is my code to retrieve an image from mysql db. Its working properly. But i... = "jdbc:mysql://localhost:3306/"; String dbName = "db"; String userName
retrieving image from mysql db with standard height and width
retrieving image from mysql db with standard height and width  Hi . Here is my code to retrieve an image from mysql db. Its working properly. But i... = "jdbc:mysql://localhost:3306/"; String dbName = "db"; String userName
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.
How to use next and previous button(or href) for database table that is retrieved from MySQL DB.  Initially,display 7or10 records on a jsp pageand when click on the NEXT button(or href link) then display next 7 records
iPhone Pick images from Photo Library
iPhone Pick images from Photo Library In this example application we are going to show you how to pick an image from photo library. To choose the photo from the photo library we required to call three different delegates
How to use next and previous button(or href) for database table that is retrieved from MySQL DB using jsp,jstl,javascript
that is retrieved from MySQL DB using jsp,jstl,javascript  when click on the next button/link then it must display next 10 record from database and same for previous to display previous 10records. Database Query like this: Select * from table
fat image from db
fat image from db   <%@ page import="java.sql.*"%> <...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost... = stmt.executeQuery("select image from regimg where id ='45'"); if (rs.next
fat image from db
fat image from db   <%@ page import="java.sql.*"%> <...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost... = stmt.executeQuery("select image from regimg where id ='45'"); if (rs.next
fat image from db
fat image from db   <%@ page import="java.sql.*"%> <...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost... = stmt.executeQuery("select image from regimg where id ='45'"); if (rs.next
fat image from db
fat image from db   <%@ page import="java.sql.*"%> <...("com.mysql.jdbc.Driver"); con = DriverManager.getConnection("jdbc:mysql://localhost... = stmt.executeQuery("select image from regimg where id ='45'"); if (rs.next
how to migrate java db to mysql
how to migrate java db to mysql  I have an aplication,for migrating java db to mysql db.how it will done
Function mysql_db_query() is deprecated
Function mysql_db_query() is deprecated  Hi, In latest version of PHP Function mysqldbquery() is deprecated. What could be the solution? Thanks
Function mysql_db_query() is deprecated
Function mysql_db_query() is deprecated  Hi, In latest version of PHP Function mysqldbquery() is deprecated. What could be the solution? Thanks
Version of mysql>mysql-connector-mxj-db-files dependency
List of Version of mysql>mysql-connector-mxj-db-files dependency
photo viwer
photo viwer  i need coding for photo viewer using jsp mysql   Please visit the following link: http://www.roseindia.net/jsp/downloadimage.shtml
How to view a list of MySQL users and their privileges?
How to view a list of MySQL users and their privileges?  Hi, How to view a list of MySQL users and their privileges? It want to view these two... command to view list of users and their privileges in MySQL database. If you have
ModuleNotFoundError: No module named 'riptide-db-mysql'
ModuleNotFoundError: No module named 'riptide-db-mysql'  Hi, My... named 'riptide-db-mysql' How to remove the ModuleNotFoundError: No module named 'riptide-db-mysql' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'boois_mysql_db_helper'
ModuleNotFoundError: No module named 'boois_mysql_db_helper'  Hi...: No module named 'boois_mysql_db_helper' How to remove the ModuleNotFoundError: No module named 'boois_mysql_db_helper' error? Thanks   Hi
upload csv to mysql db using jsp upload
upload csv to mysql db using jsp upload  Hello all, Please give me the code to uplad .csv from jsp page and insert values into MySQl db. I have a table with 8 cloumns.(MDN--varchar(30),Otafdate date,crt varchar(30),dmdn
view data from jTextArea to jtable
view data from jTextArea to jtable  good night Please help senior java all, I want to make a brief program of reading data in the text area and then on the show to the j table. I created a new scrip like below but it does
How to insert data from a combobox and textbox values into DB using JSP?
How to insert data from a combobox and textbox values into DB using JSP?  hi, How to insert a comb-box and a text box values in to DB using JSP? @DB... and textbox2? into MYSQL DB
Version of com.soywiz>korio-ext-db-mysql dependency
List of Version of com.soywiz>korio-ext-db-mysql dependency
How to map MySQL View and Hibernate framework
How to map MySQL View and Hibernate framework  I found the following while trying to access MySQL View via Hibernate. HTTP Status 500 - java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr
How to map MySQL View and Hibernate framework
How to map MySQL View and Hibernate framework  I found the following while trying to access MySQL View via Hibernate. HTTP Status 500 - java.lang.NoSuchMethodError: org.hibernate.hql.antlr.HqlBaseParser.recover(Lantlr
schema extraction from mysql
schema extraction from mysql  hi i am completely new to MySql. i need...) and password? 2)how do i export schema from existing table? 3) how do i use GUI for mysql?(still iam working in mysql console
upload photo in xcode
upload photo in xcode  how can i upload a photo in a view in xcode? i am a beginner in xcode please help me
Saving image and text in mysql db using spring?
Saving image and text in mysql db using spring?  Hii, My requirement is to save the employee details(including image) into mysql db.i want to save the image location in db .And actual image(binary formate) should save
Mysql DB backup size increases rapidly
Mysql DB backup size increases rapidly  we are using mysql 5.1 with jboss application server. recently database size increases rapidly. it goes upto 8GB. how can we optimize the DB? or shall we delete any log files? let me know
same thing i want but from db..
same thing i want but from db..  http://www.roseindia.net/tutorial/javascript/dynamicCombo.html same thing i want but from db
update the selected records from view immediatly
update the selected records from view immediatly  Hi I am extracting data form sql view to Excel(2007). I want update the Flag field (CHAR 1)in one Table as soon as i get the data form the view to excel. Is there any way I can
View the mysql querys by and my Php WebApp
View the mysql querys by and my Php WebApp  i need to debug a php web application. The problem is somewhere in the mysql query section. I need... by the mysql database. How can i do that ? Is there some script like phpmyadmin has
retrieving from db - JSP-Servlet
retrieving from db  hello' I am trying to write my first application...: rst=stmt.executeQuery("select * from books_details"); 27: %> 28...; Hi Retrive value from database Retrive data from
Image retrieval from mysql - JSP-Servlet
Image retrieval from mysql  Hai friends, I used the following code to insert image into mysql db. Db data type is blob. Database connection codings are in different file which is to be included
Maven Repository/Dependency: br.com.objectos | db-mysql
Maven Repository/Dependency of Group ID br.com.objectos and Artifact ID db-mysql. Latest version of br.com.objectos:db-mysql dependencies. # Version Release Date You can read more
Maven Repository/Dependency: br.com.objectos.way | db-mysql
Maven Repository/Dependency of Group ID br.com.objectos.way and Artifact ID db-mysql. Latest version of br.com.objectos.way:db-mysql dependencies. # Version Release Date 1
to upload a table from DB to the same html page
to upload a table from DB to the same html page  how to make this booklist table to be opened in the same html page itself using a third frame
Photo upload, Download
that this photo photo can be accessed in all of the machines from server side...Photo upload, Download  Hi I am using NetBeans IDE for developing application for java(Swings). And i am using MySQL as backend database. My
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql...;db ("test"); $term = $_POST['term']; $sql = mysql_query("select
photo album
photo album  while syncing photos to my photo album in my iphone, the photo albumj ust got crashed i guess. Under photos option i just have the camera roll option now!! What should i do to get the photo album back
photo uploading
photo uploading  i want the code upload the image in oracle database
Maven Repository/Dependency: mysql | mysql-connector-mxj-db-files
Maven Repository/Dependency of Group ID mysql and Artifact ID mysql-connector-mxj-db-files. Latest version of mysql:mysql-connector-mxj-db-files dependencies. # Version Release Date You
Upload Photo to Server
Upload Photo to Server  Hi I am using NetBeans IDE for developing application for java(Swings). And i am using MySQL as backend database. My... i am loading photo. (adsbygoogle = window.adsbygoogle || []).push
DELETE with alias reference impossible without selecting a db since MySQL 5.5.3?
DELETE with alias reference impossible without selecting a db since MySQL 5.5.3?   DELETE with alias reference impossible without selecting a db since MySQL 5.5.3
retrieving info from DB using struts?
retrieving info from DB using struts?  Hi. I was looking info about retrieving info from a database using struts. I need a .java that I suppose connects to a database and show the info on a jsp. Somebody could help me
Mysql Date from Date
Mysql Date from Date       Mysql  Date from Date Time in Mysql return the Current ... an example from 'DateTime in Mysql'. To grasp this example, we use date(current
Retrieve The Data From MySql Datbase
Retrieve The Data From MySql Datbase   How to Retrieve The Data From MYSQL database TO Use Select the Emp_id Option.And Also Search Option
How to access data yearly from DB in C# ?
How to access data yearly from DB in C# ?  how to access data yearly from database in C#. I have code but i m not able to retrieve data yearly from DB table. string date1 = dateTimePicker1.Value.Date.ToString("dd/MMM/yyyy
Ask make graph from i report and view to java Language Programming
Ask make graph from i report and view to java Language Programming  Dear sir, Please help me, i want to make a graph from mysql to i report and view to java. Please help me, give me example source code please. thank you
Read data from Excel and insert in to DB and export data from DB to Excel
Read data from Excel and insert in to DB and export data from DB to Excel  Read data from Excel and insert in to DB and export data from DB to Excel Hi, I need to read the data from excel and I need to insert the same in to DB

Ads