public static String Driver="com.microsoft.sqlserver.jdbc.SQLServerDriver"
public static String Url="jdbc:sqlserver://127.0.0.1:1433databaseName=Person"
public static String userName="sa"
public static String passWord="123456"
public static Connection conn=null
public static PreparedStatement pst=null
public static ResultSet rs=null
public static Connection GetConnection(){
try {
Class.forName(Driver)
conn=DriverManager.getConnection(Url,userName,passWord)
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace()
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
return conn
}
public static void CloseAll(Connection conn,PreparedStatement pst,ResultSet rs ){
try {
if(rs!=null){
rs.close()
rs=null
}
if(pst!=null){
pst.close()
pst=null
}
if(conn!=null){
conn.close()
conn=null
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace()
}
}
啊啊啊,0分?那我就提示你一点点算了,动态创建的话,只有规矩的使用sql包获取前台参数,运行传入的语句备份,恢复,删除,则可以使用Runtime对象.的exec方法运行dos口令.
以用户搜索为例,根据用户名来搜索:
String sql="select * from user where 1=1"if(username!=null&&!"".equals(username)){
sql+=" and username='"+username+"'"
}
每个项都判断下是否为空,然后拼sql语句就行了
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)