code :void addButton_actionPerformed(ActionEvent e)
{
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url="jdbc:odbc:estate";
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=db_estate","sa","sa");
//connection = DriverManager.getConnection(url);
statement = connection.createStatement();
String sql1= "insert into db_estate.dbo.aa(aa_id,aa_name,address,aa_area) values("+Integer.parseInt(districtid.getText())+",'"+buildingid.getText()+"','"+stac.getText()+"',"+Integer.parseInt(func.getText())+")";
statement.executeUpdate(sql1);

}
catch(Exception ex){
JOptionPane.showMessageDialog(demo_info.this,"填加数据出错","错误",JOptionPane.ERROR_MESSAGE);
//ex.printStackTrace();
}
finally{
try{
if(statement != null){
statement.close();
}
if(connection != null){
connection.close();
}
}
catch(SQLException ex){
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: "+ ex.getMessage());
System.out.println("SQLState: "+ ex.getSQLState());
System.out.println("ErrorCode: "+ ex.getErrorCode());
}
}
updated();
}
updated()方法:void updated()
{
try{
//Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//String url="jdbc:odbc:estate";
//connection = DriverManager.getConnection(url);
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
connection = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433; DatabaseName=db_estate","sa","sa");
statement = connection.createStatement();
String sql3= "select * from db_estate.dbo.aa";
rSet=statement.executeQuery(sql3);
if(rSet.next()== true)
{
String sql= "select * from db_estate.dbo.aa";
ResultSet rs=statement.executeQuery(sql);


vector.removeAllElements();
tm.fireTableStructureChanged();

while(rs.next())
{
Vector rec_vector=new Vector();
rec_vector.addElement(rs.getString(1));
rec_vector.addElement(rs.getString(2));
rec_vector.addElement(rs.getString(3));
rec_vector.addElement(rs.getString(4));

vector.addElement(rec_vector);
}
tm.fireTableStructureChanged();
}


}
catch(Exception ex){
ex.printStackTrace();
}
finally{
try{
if(statement != null){
statement.close();
}
if(connection != null){
connection.close();
}
}
catch(SQLException ex){
System.out.println("\nERROR:---------SQLException--------\n");
System.out.println("Message: "+ ex.getMessage());
System.out.println("SQLState: "+ ex.getSQLState());
System.out.println("ErrorCode: "+ ex.getErrorCode());
}
}
}出错code:(类型转换问题)
java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Value can not be converted to requested type.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseData.getInteger(Unknown Source)
at com.microsoft.jdbc.base.BaseResultSet.getInt(Unknown Source)运行结果:
database table:aa_id   smallint
aa_name  nvarchar
aa_address nvarchar
aa_area  float
请大神们帮忙修改下;THANKS