Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

jdbc--sql exception invalid object 'objectname"  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends,
below is a code to store data in a database...it gives an exception invalid object name 'Shopper2'..........Shopper2 is a table in sql database......i used create table statement
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
class Shopping implements ActionListener
{
static JFrame f1;
static JPanel p1;
JLabel shopperName;
JLabel shopperAddress;
JTextField tShopperName;
JTextField tShopperAddress;
JButton b1;
public static void main(String args[])
{
new Shopping();
}
public Shopping()
{
p1 = new JPanel();
f1 = new JFrame("Storing Data in a Datbase");
f1.setVisible(true);
f1.setSize(300,300);
f1.getContentPane().add(p1);
shopperName = new JLabel("Name");
shopperAddress = new JLabel("Address");
b1 = new JButton("Submit");
tShopperName = new JTextField(10);
tShopperAddress = new JTextField(10);
p1.add(shopperName);
p1.add(shopperAddress);
p1.add(tShopperName);
p1.add(tShopperAddress);
p1.add(b1);
b1.addActionListener(this);
}
public void actionPerformed(ActionEvent evt)
{
Object source = evt.getSource();
if(source == b1)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con=DriverManager.getConnection("jdbc dbc:HR","user1","");
PreparedStatement stat =con.prepareStatement("insert into Shopper2(vName,vAddress) values(?,?)");
stat.setString(1,tShopperName.getText());
stat.setString(2,tShopperAddress.getText());
stat.executeUpdate();
}
catch(Exception e)
{
System.out.println("Error" + e);
}
}
}
}

thank u very much...
 
Are we home yet? Wait, did we forget the tiny ad?
Download Free Java APIs to Work with Office Files and PDF
htttp://www.e-iceblue.com/free-apis.html
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!