当前位置:编程学习 > JAVA >>

java.sql.SQLException: Column not found怎么解决

数据库:
create table book(
number varchar(10),
bookname varchar(10),
publish varchar(10),
author varchar(10),
isbn varchar(10),
price varchar(10)

代码:



import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;

import javax.swing.*;
public class DelBook extends JPanel{

private JTextField number,bookname,publish,author,isbn,price;
private JLabel jnumber,jbookname,jpublish,jauthor,jisbn,jprice;
private JButton button1,button2;
PrintStream output;
DataInputStream input;
String message="";
String bookinfor[];

public DelBook()
{
this.setLayout(null);
        jnumber=new JLabel("编号");
        number=new JTextField();
        jbookname=new JLabel("书名");
        bookname=new JTextField();
        jpublish=new JLabel("出版社");
        publish=new JTextField();
        jauthor=new JLabel("作者");
        author=new JTextField();
        jisbn=new JLabel("ISBN");
        isbn=new JTextField();
        jprice=new JLabel("价格");
        price=new JTextField();
        button1=new JButton("查询");
        button2=new JButton("删除");

        jnumber.setBounds(30,20,60,26);
        jbookname.setBounds(30,100,60,26);
        jpublish.setBounds(30,130,60,26);
        jauthor.setBounds(30,160,60,26);
        jisbn.setBounds(30,190,60,26);
        jprice.setBounds(30,220,60,26);
        
        number.setBounds(110,20,120,26);
        bookname.setBounds(110,100,120,26);
        publish.setBounds(110,130,120,26);
        author.setBounds(110,160,120,26);
        isbn.setBounds(110,190,120,26);
        price.setBounds(110,220,120,26);
        
        button1.setBounds(60,60,60,30);
        button2.setBounds(60,250,60,26);

        bookname.setEnabled(false);
        publish.setEnabled(false);
        author.setEnabled(false);
        isbn.setEnabled(false);
        price.setEnabled(false);

        this.add(jnumber);
        this.add(number);
        this.add(button1);
        this.add(jbookname);
        this.add(bookname);
        this.add(jpublish);
        this.add(publish);
        this.add(jauthor);
        this.add(author);
        this.add(jisbn);
        this.add(isbn);
        this.add(jprice);
        this.add(price);       
        this.add(button2);
        

        button1.addActionListener(new ActionListener(){
         public void actionPerformed(ActionEvent e)
         {
         /*if(number.getText().toString().equals(""))
         JOptionPane.showMessageDialog(null, "编号不能为空!","修改",JOptionPane.WARNING_MESSAGE);
         */
         try{
if(number.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "图书编号不能为空","删除",JOptionPane.WARNING_MESSAGE);
String sqlstr1;
JdbcFiles conn=new JdbcFiles();
sqlstr1="select number,bookname,publish,author,isbn,price from book where convert(nvarchar(255),number)='"+number.getText()+"'";
ResultSet result=conn.executeQuery(sqlstr1);
   if(result.next()){
   {
   bookname.setText(result.getString("booknamer"));
   publish.setText(result.getString("publish"));
   author.setText(result.getString(" author"));
   isbn.setText(result.getString("isbn"));
   price.setText(result.getString("price"));

   }
}
   else
   JOptionPane.showMessageDialog(null, "当前没有该书信息","删除",JOptionPane.WARNING_MESSAGE);
}catch (ClassNotFoundException ce) {
System.out.println("SQLException:" + ce.getMessage());

} catch (SQLException ex) {
System.out.println(ex);

} catch (Exception s) {
s.printStackTrace();
}

}


});
      

button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
     try{

String sqlstr2="delete from book where convert(nvarchar(255),number)='"+number.getText()+"'";
int k=-1;
JdbcFiles conn1=new JdbcFiles();
k=conn1.insert(sqlstr2);
if(number.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "编号不能为空","修改",JOptionPane.WARNING_MESSAGE);
else
if(bookname.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "书名不能为空","修改",JOptionPane.WARNING_MESSAGE);
else
if(publish.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "出版社不能为空","修改",JOptionPane.WARNING_MESSAGE);
else
if(author.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "作者不能为空","修改",JOptionPane.WARNING_MESSAGE);
else
if(isbn.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "ISBN不能为空","修改",JOptionPane.WARNING_MESSAGE);
else
if(price.getText().toString().equals(""))
JOptionPane.showMessageDialog(null, "价格不能为空","修改",JOptionPane.WARNING_MESSAGE);
else if (k > -1)
{
JOptionPane.showMessageDialog(null, "删除成功!", "删除",JOptionPane.WARNING_MESSAGE);
conn1.close();
} else
JOptionPane.showMessageDialog(null, "删除失败!", "删除",JOptionPane.WARNING_MESSAGE);


                 }catch(ClassNotFoundException ce){
                     System.out.println("SQLException:"+ce.getMessage());

               }catch(SQLException ex){
             System.out.println(ex);

                 }catch(Exception s){
               s.printStackTrace();
                       }
                      }
             });
setSize(250,380);
this.setVisible(true);
}
 public static void main(String[] args)
  {
 DelBook app1=new DelBook();
  
  
  }
} --------------------编程问答-------------------- 已解决! --------------------编程问答-------------------- 恭喜 --------------------编程问答-------------------- 看看,先了解一下 --------------------编程问答-------------------- 我用java查询access数据库时用:
String sql="SELECT Name FROM table1 where Age = (SELECT Age FROM table1 where Name='李四')";
结果出现:
姓名:李四java.sql.SQLException: Column not found

java.sql.SQLException: Column not found这个问题是怎么解决的啊? --------------------编程问答-------------------- 这个异常表示你查询的某个列在表中找不到,比如Name或Age在表table1中没有
--------------------编程问答-------------------- 你表中列应该和数据库有对应的,有一个没有对应到数据库中的字段
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,