不能在servlet里使用SqlCommand对象?

来源:百度知道 编辑:UC知道 时间:2024/05/28 20:31:10
MyEclipse 里 我创建了一个 servlet 写一个数据层 直接在里面写SqlCommand com = new SqlCommand() 结果SqlCommand下划了条波浪线 点开叉叉以后 没有叫我倒包 只有叫我创建一个SqlCommand
如果不能用SqlCommand 那我应该怎么插入数据库呢 本来是想这样写的
SqlCommand com = new SqlCommand(sql,conn);
int insertnews = com.ExecuteNonQuery(sql);

请各位大哥指点 万分感谢!!
那可是我应该怎么写 就是因为写 .NET 这段时间 JAVA都快忘完了 大哥 请指点啊

哇撒 servlet是java的
C#是。net的
你怎么混淆了
SqlCommand 这是。net的
在命名空间using System.Data.SqlClient;
你写的代码都正确 可惜这是。net的 嘿嘿

我给你一个吧
package bean;
import java.sql.*;
public class DataBase{
String sqlStr;
Connection con;
String str,us,pwd;
public DataBase(String str,String us,String pwd){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
this.str=str;
this.us=us;
this.pwd=pwd;
}catch(Exception ex){}
}

public boolean open(){
try{
if(con==null||con.isClosed())
con= DriverManager.getConnection("jdbc:odbc:"+str,us,pwd);
return true;
}catch(Exception ex){
return false;
}
}

public boolean close(){
try{
if(con==null)
return false;
con.close();
return true;
}catch(Exception ex){
ex.printStackTrace();
return false;
}
}