Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners View Photo From Db MySql
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


hendra
View Photo From Db MySql
2 Answer(s)      2 years and 6 months ago
Posted in : Java Beginners


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


Advertisement
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
struts cfg file for DispatchAction with mysql db
struts cfg file for DispatchAction with mysql db  IN STRUTS CFG FILE: <action-mappings> <action path="/Welcome" forward="/welcomeStruts.jsp"/> <action path="/Test
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
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
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
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
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
how to insert, retrieve data from,to db(code)....
how to insert, retrieve data from,to db(code)....  Hi..... i ve... that data will b stored in db(m using sybase). 2.also hw to retrieve the data from db. cn u plz tel me the code in detail.n i thk it shud b written in jdbc
 

 

 

DMCA.com