这段代码:sName = File.BaseName(value2,true)提示错误信息:选中的内容 第1行:模块 File.BaseName 命令出错:非法的参数类型
时间: 2024-06-01 17:12:23 浏览: 99
这段代码中,value2的数据类型可能不符合File.BaseName函数所要求的参数类型。具体来说,该函数要求传入的参数必须是字符串类型,而value2可能不是字符串类型,导致函数调用时出现错误。
解决方法可以尝试将value2转换为字符串类型,例如使用str()函数将其转换为字符串,即:
sName = File.BaseName(str(value2),true)
相关问题
for _size in goods['sizes']: if Size.objects.filter(sname=_size[0]).count() == 1: size = Size.objects.get(sname=_size[0]) else: size = Size.objects.create(sname=_size[0]) sizes.append(size) colors = [] for _color in goods['colors']: color = Color.objects.create(colorname=_color[0], colorurl=_color[1]) colors.append(color) for _spec in goods['specs']: goodsdetails = GoodsDetailName.objects.create(gdname=_spec[0]) for img in _spec[1]: GoodDetail.objects.create(goods=good,goodsdname=goodsdetails,gdurl=img) for c in colors: for s in size: Inventory.objects.create(count=100,goods=good, color=c, sizes=s)TypeError: Inventory() got an unexpected keyword argument 'size'如何修正
这个错误是因为 Inventory 模型中没有 "size" 字段,而在创建 Inventory 对象时使用了 "size" 参数。需要将 "size" 改为 "sizes",即:
```
Inventory.objects.create(count=100, goods=good, color=c, sizes=s)
```
编写程序,实现对数据库StudentInfo中的表student进行插入操作.要求使用预处理语句对象PreparedStatement完成以下数据的插入: insert into student values('001','张三',18,'女') 注:给定数据库登录用户名:sa,密码:123. Input.jsp: 请输入待新增的学生信息 学号: 姓名: 年龄: 性别: addStudent.jsp: <% String url="jdbc:sqlserver://localhost;databaseName=StudentInfo"; request.setCharacterEncoding("utf-8"); String sno = request.getParameter("sno"); String sname = request.getParameter("sname"); int sage = Integer.valueOf(request.getParameter("sage")); String sex = request.getParameter("sex"); try{ //补全此部分代码 } // 捕获异常 catch(SQLException ex) { System.out.println ("\n*** 发生SQL异常 ***\n"+ex.getMessage()); } catch(ClassNotFoundException ex) { System.out.println(ex); }
addStudent.jsp:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Add Student</title>
</head>
<body>
<h1>Add Student</h1>
<form action="insertStudent.jsp" method="post">
<label for="sno">学号:</label>
<input type="text" id="sno" name="sno" /><br>
<label for="sname">姓名:</label>
<input type="text" id="sname" name="sname" /><br>
<label for="sage">年龄:</label>
<input type="text" id="sage" name="sage" /><br>
<label for="sex">性别:</label>
<input type="text" id="sex" name="sex" /><br>
<input type="submit" value="提交" />
</form>
</body>
</html>
```
insertStudent.jsp:
```
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert Student</title>
</head>
<body>
<%
String url="jdbc:sqlserver://localhost;databaseName=StudentInfo";
request.setCharacterEncoding("utf-8");
String sno = request.getParameter("sno");
String sname = request.getParameter("sname");
int sage = Integer.valueOf(request.getParameter("sage"));
String sex = request.getParameter("sex");
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(url,"sa","123");
String sql = "insert into student values(?,?,?,?)";
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setString(1, sno);
pstmt.setString(2, sname);
pstmt.setInt(3, sage);
pstmt.setString(4, sex);
int num = pstmt.executeUpdate();
if(num > 0){
out.print("插入成功!");
}
pstmt.close();
conn.close();
}
catch(SQLException ex){
System.out.println ("\n*** 发生SQL异常 ***\n"+ex.getMessage());
}
catch(ClassNotFoundException ex){
System.out.println(ex);
}
%>
</body>
</html>
```
阅读全文