是不是你sql语句里地表名写错了呀
解决方案 »
- sql server 不允许从数据类型 varbinary 到 date 的隐式转换
- jsp如何生成一个随机数,记载进数据库
- httpclient 验证码登陆问题
- javascript 实现IE按F11的效果并去掉工具栏和地址栏
- Java中反射的应用
- sql 的代码编写的错误,在线等!谢谢
- 有3个竖向并排的独立表格,怎样使右边的两个表格高度自动和左边第一个表格对齐
- 我到底应过去当老师还是做程序员呢?
- 为什么我的<% out.print("this the second test !"); %>没有显示在网页上?
- tomcat启动时报错,出现Cannot create PoolableConnectionFactory
- 救急,关于表单提交的问题!!!!!!!!!!!!!!
- 高分求cookie问题,可以读取也有JSESSIONID,就是无法写入哭!!!
----------------------------------------------------
你是连接内容一样的数据库吗?你看看你的服务器地址有无打错,很可能是地址错了,要不然就是上面的说法了,最好你把代码贴出来看看。
{
public String sql_driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
public String sql_url = "jdbc:microsoft:sqlserver://localhost:1433;";
public String sql_DBName = "DatebaseName=shopping;";
public String user = "user=sa;";
public String pwd = "password=sa"; Connection conn = null;
Statement stmt = null;
ResultSet rs = null; public boolean setDriver(String drv)
{
this.sql_driver = drv;
return true;
} public String getDriver()
{
return this.sql_driver;
} public boolean setUrl(String url)
{
this.sql_url = url;
return true;
} public boolean setDBName(String dbname)
{
this.sql_DBName = dbname;
return true;
} public String getDBName()
{
return this.sql_DBName;
} public boolean setUser(String user)
{
this.user = user;
return true;
} public String getUser()
{
return this.user;
} public boolean setPwd(String pwd)
{
this.pwd = pwd;
return true;
} public String getPwd()
{
return this.pwd;
} public DBConn()
{
try{
Class.forName(sql_driver);//
this.conn = DriverManager.getConnection(sql_url+sql_DBName+user+pwd);
this.stmt = this.conn.createStatement();
}catch(Exception e){
System.out.println(e.toString());
}
} //
public ResultSet executeQuery(String strSql)
{
try{
this.rs = stmt.executeQuery(strSql);
return this.rs;
}catch(SQLException e){
System.out.println(e.toString());
return null;
}catch(NullPointerException e){
System.out.println(e.toString());
return null;
}
} //
public boolean execute(String strSql)
{
try{
if(this.stmt.executeUpdate(strSql) == 0)
return false;
else
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}catch(NullPointerException e){
System.out.println(e.toString());
return false;
}
} //
public boolean rs_absolute(int row)
{
try{
this.rs.absolute(row);
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
} public void rs_afterLast()
{
try{
this.rs.afterLast();
}catch(SQLException e){
System.out.println(e.toString());
}
} public void rs_beforeFirst()
{
try{
this.rs.beforeFirst();
}catch(SQLException e){
System.out.print(e.toString());
}
} public void rs_close()
{
try{
this.rs.close();
}catch(SQLException e){
System.out.print(e.toString());
}
} public void rs_deleteRow()
{
try{
this.rs.deleteRow();
}catch(SQLException e){
System.out.print(e.toString());
}
} public boolean rs_first()
{
try{
this.rs.first();
return true;
}catch(SQLException e){
System.out.print(e.toString());
return false;
}
} public String rs_getString(String column)
{
try{
return this.rs.getString(column);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
} //
//
//
public String rs_getHtmlString(String column)
{
try{
String str1 = this.rs.getString(column);
String str2 = "\r\n";
String str3 = "<br>";
return this.replaceAll(str1,str2,str3);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
}
//
private static String replaceAll(String str1,String str2,String str3)
{
StringBuffer strBuf = new StringBuffer(str1);
int index=0;
while(str1.indexOf(str2,index)!=-1)
{
index=str1.indexOf(str2,index);
strBuf.replace(str1.indexOf(str2,index),str1.indexOf(str2,index)+str2.length(),str3);
index=index+str3.length(); str1=strBuf.toString();
}
return strBuf.toString();
} public int rs_getInt(String column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
} public int rs_getInt(int column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
} public boolean rs_next()
{
try{
return this.rs.next();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
} //
public boolean hasData()
{
try{
boolean has_Data = this.rs.first();
this.rs.beforeFirst();
return has_Data;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
} public boolean rs_last()
{
try{
return this.rs.last();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
} public boolean rs_previous()
{
try{
return this.rs.previous();
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public static void main(String args[])
{
try{
DBConn myconn = new DBConn();
ResultSet rs = myconn.executeQuery("select * from user_info");
while (myconn.rs.next())
{
int id = myconn.rs_getInt("id") + 1;
System.out.print(id);
System.out.println(myconn.rs_getInt("id") + myconn.rs_getString("name"));
//System.out.println('\n' + myconn.rs_getHtmlString("name"));
//System.out.println(myconn.rs.getString("name") + myconn.rs_getInt(1));
}
}catch(Exception e){
System.err.println(e.toString());
}
}
}
取字段的顺序要和表字段顺序保持一致的 ..........
public class testsqlserver{
public static void main(String[] args){
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://xn-yang:1433;DatebaseName=test";
String user="sa";
String pass="sa";
Connection conn=DriverManager.getConnection(url,user,pass);
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet rs = stmt.executeQuery("select * from tbluser where name='xn'");
System.out.println("Connection");
}catch(Exception e){
System.out.println(e.toString());
}
}
}还是报错,同样的问题!
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);里面的参数去掉.
你在本地用BEAN能连接数据库,说明你的JDBC下的三个.JAR文件已经加入CLASSPATH
而中JSP中的连接数据库不能使用,说明你的JDBC三个.JAR文件没有配置到WEB-INF\LIB下