急急急 java 需要 <表示符> 高手给看一下吧

package com.new;

import oa.sys.*;
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
****************************************************
*类名称: Del<br>
*类功能: 删除新闻<br>
*
****************************************************
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Del extends HttpServlet{
private int temp;
private String sqli;
private int id;
private int infoid;
private HttpSession session=null;
private ResultSet rs=null;
private Statement stmt=null;

public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
request.setCharacterEncoding("gb2312");
response.setContentType("text/html; charset=gb2312");
Str str=new Str();
Db db=new Db();
PrintWriter out=response.getWriter();
session=request.getSession();
try{
id=Integer.parseInt((String)session.getAttribute("id"));
}catch(Exception e){
e.printStackTrace();
}
try{
infoid=Integer.parseInt((String)request.getParameter("infoid"));
}catch(Exception e){
e.printStackTrace();
}
if(id==-1){
sqli="DELETE FROM new WHERE infoid="+infoid;
}else{
sqli="DELETE FROM new WHERE accepter="+id+" AND infoid="+infoid;
}
try {
stmt=db.getStmt();
temp=stmt.executeUpdate(sqli);
} catch (SQLException e) {
e.printStackTrace();
}finally{
db.close();
RequestDispatcher dispatcher=request.getRequestDispatcher("view");
dispatcher.forward(request,response);
}
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException{
doPost(request,response);
}
}

编译结果:

Del.java:1:需要 <标识符〉
package com.new;
^
1 错误
Str 是字符串转化的javabeans
Db 里面连接数据库的代码
public class Db {
private Connection con;
private Statement stmt;
private ResultSet rs;
private PreparedStatement pstmt;
public static int error=0;

/***************************************************
*函数名称: getCon()<br>
*函数功能: 获取数据库连接<br>
*返回值: 无<br>
*参数说明: 无<br>
*
****************************************************/
public static synchronized Connection getCon()throws Exception{
Context ctx;
DataSource ds;
try{
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:comp/env/jdbc/OA");
System.err.println();
System.err.println("数据连接+"+(++error));
return ds.getConnection();
}catch(SQLException e){
System.out.print(e);
throw e;
}
catch(NamingException e){
System.out.print(e);
throw e;
}
}

把包名改了,new 是java的关键字

我刚试了一下,发现有以下错误提示:
Invalid package name. 'new' is not a valid Java identifier
意思是:无效的包名,'new'不是有效的标识符

建议你以后取名的时候不要用java的关键字
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-05-16
Str str=new Str(); ←貌似应该是 String str=new String(); 吧
Db db=new Db(); ← 貌似这里应该是个 Connection 应该还有个数据库连接的类 Db 里面写了连接数据库的代码,在哪里???

解释下这二个是什么东东? 从哪里来的?
第2个回答  2008-05-16
包名改了... com.mnew
相似回答