com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'Monkey' 无效。
程序员文章站
2024-02-20 10:50:28
...
主要代码
package chp13;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;
public class Test3 {
private static Logger logger=Logger.getLogger(Test3.class.getName());
public static void main(String[] args) {
// TODO Auto-generated method stub
Connection conn=null;
Statement stmt=null;
String name="闹闹";
int health=100;
int love=0;
String strain="猕猴";
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error(e);
}
try {
conn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabassName=epet","sa","1111111");
stmt=conn.createStatement();
StringBuffer sbSql=new StringBuffer(
"insert into Monkey (name,health,love,strain) values('");
sbSql.append(name+"',");
sbSql.append(health+",");
sbSql.append(love+",'");
sbSql.append(strain+"')");
stmt.execute(sbSql.toString());
logger.info("插入小猴子信息成功!");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error(e);
}finally {
try {
if(null!=stmt) {
stmt.close();
}if(null!=conn) {
conn.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
logger.error(e);
}
}
}
}
异常警告
com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'Monkey' 无效。
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1655)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:885)
at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:778)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:191)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:166)
at com.microsoft.sqlserver.jdbc.SQLServerStatement.execute(SQLServerStatement.java:751)
at chp13.Test3.main(Test3.java:37)
ERROR - com.microsoft.sqlserver.jdbc.SQLServerException: 对象名 'Monkey' 无效。
哪里出错了