java—将数据连接到数据库中的一行

kpbwa7wx  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(196)

我把数据放在同一行有问题。
这是我的ui显示:

数据库:

我想创建一个位置,如果用户同时分配腿部和手臂练习,数据库将显示插入一行的腿部和手臂练习。但是现在,当我把它们插入到一起时,数据库中的数据将在两个不同的行中。
.js代码

<%@page import="java.sql.*"%>

<html>
<body>
<%

    String[] id = request.getParameterValues("assignchkbox");
    String armID = request.getParameter("ArmID");
    String armnumber    = request.getParameter("Armnumber");
    int count=0;
    Connection conn = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        // Step 2: Define Connection URL
        String connURL = "jdbc:mysql://localhost/medicloud?user=root&password=root";
        // Step 3: Establish connection to URL
        conn = DriverManager.getConnection(connURL);

        if (id != null)
        {
            for( int i=0; i<id.length; i++){

                String sqlStr = "Insert into assign(ArmID,Armnumber) Value(?,?)";
                PreparedStatement pstmt = conn.prepareStatement(sqlStr);
                pstmt.setInt(1, Integer.parseInt(id[i]));
                pstmt.setString(2,armnumber);
                //pstmt.setInt(1, Integer.parseInt(ids[i]));
                int rec=pstmt.executeUpdate();
                if (rec==1){
                    count++;

                }
            }

        }

%>

<%
    String[] id1 = request.getParameterValues("assignchkbox1");
    String legID = request.getParameter("LegID");
    String legnumber = request.getParameter("Legnumber");
    int count1=0;
    Connection conn1 = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        // Step 2: Define Connection URL
        String conn1URL = "jdbc:mysql://localhost/medicloud?user=root&password=root";
        // Step 3: Establish connection to URL
        conn1 = DriverManager.getConnection(conn1URL);

        if (id1 != null)
        {
            for( int i=0; i<id1.length; i++){

                String sqlStr = "Insert into assign(LegID,Legnumber) Value(?,?)";
                PreparedStatement pstmt = conn.prepareStatement(sqlStr);
                pstmt.setInt(1, Integer.parseInt(id1[i]));
                pstmt.setString(2,legnumber);
                //pstmt.setInt(1, Integer.parseInt(ids[i]));
                int rec=pstmt.executeUpdate();
                if (rec==1)
                    count1++;
            }

        }

%>

<form action="assign.jsp" method="post">
        <label><%=count%> arm record(s) assigned!!</label>
        <td style width="50%">

    </form>

    <form action="assign.jsp" method="post">
        <label><%=count1%> leg record(s) assigned!!</label>
        <p><input type="submit" value="Return" name="ReturnBtn" /></p>
    </form>
<%
        conn.close();
        conn1.close();
    }finally{

    }
    }catch (Exception e) {
        e.printStackTrace();
    }
%>
</body>
</html>

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题