当前位置: 技术问答>java相关
8个错误,大家帮我找找?
来源: 互联网 发布时间:2017-03-18
本文导语: package Db; import java.sql.*; import BK.*; import java.util.*; public class DbBook { Connection Conn=null; Statement stmt=null; String SDBDriver="conn.jnetdirect.jsql.JSQLDriver"; String sConnStr="jdbc:JSQLConnect://localhost/master"...
package Db;
import java.sql.*;
import BK.*;
import java.util.*;
public class DbBook
{
Connection Conn=null;
Statement stmt=null;
String SDBDriver="conn.jnetdirect.jsql.JSQLDriver";
String sConnStr="jdbc:JSQLConnect://localhost/master";
public DbBook()
{
try{
Class.forName("conn.jnetdirect.jsql.JSQLDriver");
Conn=DriverManager.getConnection(sConnStr,"sa","");
stmt=Conn.createStatement();
}catch(Exception e)
{
System.err.println(e);
}
}
public Vector getBook(int category,javax.servlet.jsp.jspWriter out,String keyword)
{
Vector vBook=new Vector();
ResultSet rs;
String SQL="";
try{
if(keyword==null)
SQL="select * from book where category='"+category+"'";
else {
if(category==0)
SQL="select * from book where name like'%"+keyword+"%'";
else SQL="select * from book where category='"+category+"'and name like'%"+keyword+"%'";
}
rs=stmt.executeQuery(SQL);
while(rs.next())
{
Book book=new Book();
book.id=rs.getLong("id");
book.name=rs.getString("name");
book.price=rs.getFloat("price");
book.category=rs.getInt("category");
book.quantity=rs.getLong("quantity");
vBook.add(book);
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return vBook;
}
public BookgetABook(long saleid,javax.servlet.jsp.JspWriter out)
{
Book book=new Book();
try{
ResultSet rs=stmt.executeQuery("select * from book where id='"+saleid+"'");
while(rs.next())
{
book.id=rs.getLong("id");
book.name=rs.getString("name");
book.price=rs.getFloat("price");
book.category=rs.getInt("category");
book.quantity=rs.getLong("quantity");
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return book;
}
public BookDetail getDetail(long bookid,javax.servlet.jsp.JspWriter out)
{
BookDetail bookdtl=new BookDetail();
try{
ResultSet rs=stmt.executeQuery("select * from book_detail where bookid='"+bookid+"'");
while(rs.next())
{
bookdtl.id=rs.getLong("id");
bookdtl.bookid=rs.getLong("bookid");
bookdtl.author=rs.getString("author");
bookdtl.introduce=rs.getString("introduce");
bookdtl.publisher=rs.getString("publisher");
bookdtl.pagenum=rs.getInt("pagenum");
bookdtl.edition=rs.getString("edition");
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return bookdtl;
}
public decrease(long saleid,int num)
{
try{stmt.executeQuery("update book set quantity=quantity-"+num+" where id="+saleid+"");
}catch(Exception e)
{
System.err.println(e);
return null;
}
}
public long getBookId(String name)
{
ResultSet rs=null;
long id=-1;
try{rs=stmt.executeQuery("select * from book where name='"+name+"'");
while(rs.next())
{id=rs.getLong("id");}
}catch(Exception e)
{
System.err.println(e);
return -1l;
}
return id;
}
public boolean addBook(int category,String name,String author,float price,String publisher,int pagenum,String edition,int quantity,String intro)
{
long saleid=-1l;
ResultSet rs=null;
try{rs=stmt.executeQuery("select * from book where name='"+name+"'");
while(rs.next())
{saleid=rs.getLong("id");}
}catch(Exception e)
{
System.err.println(e);
return false;
}
if(saleid!=-1l){//ÒѾ´æÔÚ
try{
stmt.executeUpdate("update book set quantity=quantity+"+quantity+" where id="+saleid);
}catch(Exception e){
System.err.println(e);
return false;
}
}else{
try{
stmt.executeUpdate("insert into book_detail values('"+bookid+"','"+author+"','"+publisher+"','"+pagenum+"','"+edition+"','"+intro+"')");
}catch(Exception e)
{
System.err.println(e);
return false;
}
return true;
}
}
public boolean destroy()
{
try{
Conn.close();
}catch(Exception e)
{
return false;
}
return true;
}
}
import java.sql.*;
import BK.*;
import java.util.*;
public class DbBook
{
Connection Conn=null;
Statement stmt=null;
String SDBDriver="conn.jnetdirect.jsql.JSQLDriver";
String sConnStr="jdbc:JSQLConnect://localhost/master";
public DbBook()
{
try{
Class.forName("conn.jnetdirect.jsql.JSQLDriver");
Conn=DriverManager.getConnection(sConnStr,"sa","");
stmt=Conn.createStatement();
}catch(Exception e)
{
System.err.println(e);
}
}
public Vector getBook(int category,javax.servlet.jsp.jspWriter out,String keyword)
{
Vector vBook=new Vector();
ResultSet rs;
String SQL="";
try{
if(keyword==null)
SQL="select * from book where category='"+category+"'";
else {
if(category==0)
SQL="select * from book where name like'%"+keyword+"%'";
else SQL="select * from book where category='"+category+"'and name like'%"+keyword+"%'";
}
rs=stmt.executeQuery(SQL);
while(rs.next())
{
Book book=new Book();
book.id=rs.getLong("id");
book.name=rs.getString("name");
book.price=rs.getFloat("price");
book.category=rs.getInt("category");
book.quantity=rs.getLong("quantity");
vBook.add(book);
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return vBook;
}
public BookgetABook(long saleid,javax.servlet.jsp.JspWriter out)
{
Book book=new Book();
try{
ResultSet rs=stmt.executeQuery("select * from book where id='"+saleid+"'");
while(rs.next())
{
book.id=rs.getLong("id");
book.name=rs.getString("name");
book.price=rs.getFloat("price");
book.category=rs.getInt("category");
book.quantity=rs.getLong("quantity");
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return book;
}
public BookDetail getDetail(long bookid,javax.servlet.jsp.JspWriter out)
{
BookDetail bookdtl=new BookDetail();
try{
ResultSet rs=stmt.executeQuery("select * from book_detail where bookid='"+bookid+"'");
while(rs.next())
{
bookdtl.id=rs.getLong("id");
bookdtl.bookid=rs.getLong("bookid");
bookdtl.author=rs.getString("author");
bookdtl.introduce=rs.getString("introduce");
bookdtl.publisher=rs.getString("publisher");
bookdtl.pagenum=rs.getInt("pagenum");
bookdtl.edition=rs.getString("edition");
}
rs.close();
}catch(Exception e)
{
System.err.println(e);
}
return bookdtl;
}
public decrease(long saleid,int num)
{
try{stmt.executeQuery("update book set quantity=quantity-"+num+" where id="+saleid+"");
}catch(Exception e)
{
System.err.println(e);
return null;
}
}
public long getBookId(String name)
{
ResultSet rs=null;
long id=-1;
try{rs=stmt.executeQuery("select * from book where name='"+name+"'");
while(rs.next())
{id=rs.getLong("id");}
}catch(Exception e)
{
System.err.println(e);
return -1l;
}
return id;
}
public boolean addBook(int category,String name,String author,float price,String publisher,int pagenum,String edition,int quantity,String intro)
{
long saleid=-1l;
ResultSet rs=null;
try{rs=stmt.executeQuery("select * from book where name='"+name+"'");
while(rs.next())
{saleid=rs.getLong("id");}
}catch(Exception e)
{
System.err.println(e);
return false;
}
if(saleid!=-1l){//ÒѾ´æÔÚ
try{
stmt.executeUpdate("update book set quantity=quantity+"+quantity+" where id="+saleid);
}catch(Exception e){
System.err.println(e);
return false;
}
}else{
try{
stmt.executeUpdate("insert into book_detail values('"+bookid+"','"+author+"','"+publisher+"','"+pagenum+"','"+edition+"','"+intro+"')");
}catch(Exception e)
{
System.err.println(e);
return false;
}
return true;
}
}
public boolean destroy()
{
try{
Conn.close();
}catch(Exception e)
{
return false;
}
return true;
}
}
|
public decrease(long saleid,int num)
问题一样,还是没有返回类型,如果是不需要返回的,就写
public void decrease(long saleid,int num)
并且把下面出错的 return null删掉.
问题一样,还是没有返回类型,如果是不需要返回的,就写
public void decrease(long saleid,int num)
并且把下面出错的 return null删掉.
|
你的环境里没有JspWrite这个类,去载一个.
两个return的错误由上两个解决了.
最后一个错:在这个方法里bookid没有定义.其他地方都有定义为long的.这里漏了.
两个return的错误由上两个解决了.
最后一个错:在这个方法里bookid没有定义.其他地方都有定义为long的.这里漏了.
|
JBOSS我不懂,但起码你的java程序应该要import javax.servlet.jsp.*;
一般是不会有javax包的,我就是去sun载的.
一般是不会有javax包的,我就是去sun载的.
|
public BookgetABook(long saleid,javax.servlet.jsp.JspWriter out)
漏一个空格,当然就认为没有返回类型了.
public Book getABook(long saleid,javax.servlet.jsp.JspWriter out)
漏一个空格,当然就认为没有返回类型了.
public Book getABook(long saleid,javax.servlet.jsp.JspWriter out)
|
1. public BookgetABook() 没有返回类型
2. public decrease() 没有返回类型
3,4,5. 加上import javax.servlet.jsp.*
6,7. 返回值不正确和1,2的错误有关
2. public decrease() 没有返回类型
3,4,5. 加上import javax.servlet.jsp.*
6,7. 返回值不正确和1,2的错误有关
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。