日期:2014-05-20 浏览次数:20661 次
public class UserSystem { public static void main(String args[]){ UserSystemDAO UserSystemDAO=new UserSystemDAO(); } } import java.sql.*; public class UserSystemDAO { String insertSql="insert into table_usersystem_dictionary values(?,?,?,?)"; UserSystemDAO(){ executeSQL(); } private void executeSQL(){ UserSystemDB userSystemDB=new UserSystemDB(); PreparedStatement preparedStatement=null; Connection connection=userSystemDB.createConnection(); try{ preparedStatement=connection.prepareStatement(insertSql); preparedStatement.setString(1, "95002"); preparedStatement.setString(2,"user"); preparedStatement.setString(3,"shl"); preparedStatement.setString(4,"001"); preparedStatement.addBatch(); preparedStatement.executeBatch(); preparedStatement.close(); System.out.println("Insert success"); } catch(Exception e){e.printStackTrace();} finally{ try{ connection.close(); } catch(Exception e){e.printStackTrace();} } } } import java.sql.Connection; import java.sql.DriverManager; public class UserSystemDB { public Connection createConnection(){ Connection connection=null; try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); //String url="jdbc:odbc:argon"; String url="jdbc:microsoft:sqlserver://Localhost:1433;DatabaseName=user"; connection=DriverManager.getConnection(url,"sa",""); System.out.println("JDBC-ODBC的驱动程序注册成功"); } catch(Exception e){ e.printStackTrace(); System.out.println("找不到驱动程序"); } return connection; } }
------解决方案--------------------
更新用preparedStatement.update 你看下java基础吧
------解决方案--------------------
更新是这个preparedStatement.excuteupdate 2楼错了 不好意思