我用4个java类写了一个将信息插入数据库的程序 第一个类:DBTool数据库连接类,里边只有数据库连接和数据库关闭方法
第二个类:新闻javaBean类 第三个类:新闻插入数据库方法类 第四个类:Test测试类,传值调用方法,将值插入进数据库,刚开始我用JDBC-ODBC桥接,出现java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性下面是我第三个类的代码
package dao;
import java.sql.*;
import beans.NewsType;
import dao.DBTool;
public class NewsTypeDAO {
public NewsTypeDAO() {
} public void addNewsType(NewsType type){
DBTool db = new DBTool();
Connection con = db.open();
String sql = "insert into firstleveltitle values(?,?,?)";
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(sql);
pstmt.setString(1,type.getName());
pstmt.setString(2,type.getCreater());
// pstmt.setString(3,"200-11-12");
pstmt.setDate(3,new java.sql.Date(type.getCreaterTime().getTime())); //这一行提示错误
pstmt.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
finally{
db.close(con,pstmt,null);
}
}
}
就是错误那一行的事,然后我把错误那一行给注释掉,改成被注释掉的那一行,就不提示错误了,而且直接就插进去了。
但如果我改成用JDBC驱动的话 那一行错误的代码就可以执行了。为什么啊?
第二个类:新闻javaBean类 第三个类:新闻插入数据库方法类 第四个类:Test测试类,传值调用方法,将值插入进数据库,刚开始我用JDBC-ODBC桥接,出现java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性下面是我第三个类的代码
package dao;
import java.sql.*;
import beans.NewsType;
import dao.DBTool;
public class NewsTypeDAO {
public NewsTypeDAO() {
} public void addNewsType(NewsType type){
DBTool db = new DBTool();
Connection con = db.open();
String sql = "insert into firstleveltitle values(?,?,?)";
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(sql);
pstmt.setString(1,type.getName());
pstmt.setString(2,type.getCreater());
// pstmt.setString(3,"200-11-12");
pstmt.setDate(3,new java.sql.Date(type.getCreaterTime().getTime())); //这一行提示错误
pstmt.executeUpdate();
} catch (SQLException ex) {
ex.printStackTrace();
}
finally{
db.close(con,pstmt,null);
}
}
}
就是错误那一行的事,然后我把错误那一行给注释掉,改成被注释掉的那一行,就不提示错误了,而且直接就插进去了。
但如果我改成用JDBC驱动的话 那一行错误的代码就可以执行了。为什么啊?
Calendar cd=Calendar.getInstance();
cd.getTime();