Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc--sql exception invalid object 'objectname"

 
Peter Wong
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic