Bookmark Topic Watch Topic
  • New Topic

Data input from app to database

 
egbai mmumene
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'v been working on a movie library but every time i add a movie name in my app i get an error message sayin unknown column which is usually d name i put in to my app e.g if i add movie name: spiderman i get error message (unknown column 'spider man' in 'field list')
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
It sounds like you are building up aa select statement, and are not putting the values in quotes it should end up looking like

Insert into (...) values ('spiderman');
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
and welcome the the ranch
 
egbai mmumene
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Report post to moderator
tnx but its still not working. heres the code
package mm.main;
import java.awt.event.*;
import javax.swing.*;
import java.awt.Container;
import java.awt.FlowLayout;
import java.sql.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author smile
*/
public class moviemethod extends JFrame implements ActionListener{
private JButton entry;
private JLabel entrylabel;
private JTextField entryno;
private JTextField entrytext;
DBOperator login;
Statement stat;
ResultSet rs;
public moviemethod(){
}
public void entry(){
setVisible(true);
setLayout( new FlowLayout() );
Container pane = getContentPane();
setSize( 400, 200 );
entrylabel = new JLabel( "Movie name" );
entrytext = new JTextField(15);
entryno = new JTextField(3);
entry = new JButton( "enter" );
pane.add( entrylabel );
pane.add( entrytext );
pane.add( entryno );
pane.add( entry );
entry.addActionListener(this);
}

public void actionPerformed(ActionEvent event){
Object source = event.getSource();
if(source == entry){
try{
login = new DBOperator();
stat = login.getstatement();
String entrytxt;
int etxt = Integer.parseInt(entryno.getText());
entrytxt = entrytext.getText();
rs = stat.executeQuery("SELECT entryname, entryno FROM users");
stat.executeUpdate("INSERT INTO users (entryname, entryno) " +
"VALUES(" + entrytxt + ", '" + etxt + "')");
}
catch( SQLException ex ){
ex.printStackTrace();
}




}
}
}
 
egbai mmumene
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Report post to moderator
need help
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
  • Report post to moderator
I would definitely recommend that you use a PreparedStatement rather than a Statement. There are several reasons why you should do that except when it's absolutely impossible to arrange it, and one of them is that you don't have horrible code full of two different kinds of quotes which it's easy to get wrong.
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
stat.executeUpdate("INSERT INTO users (entryname, entryno) " +
"VALUES(" + entrytxt + ", '" + etxt + "')");

I am presuming entrytxt is a varchar and you don't have ' ' around it
 
egbai mmumene
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Report post to moderator
Tnx that error has been defeated but I'm getting an error message saying entry to long for column' entryname' really frustrated
 
Wendy Gibbons
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
look at the database how long is the entryname column, now what are you trying to insert?
 
    Bookmark Topic Watch Topic
  • New Topic