将数据连接到数据库的单行中

时间:2018-07-05 01:16:47

标签: java mysql database eclipse

将数据放在同一行时遇到问题。

这是我的界面显示:

enter image description here

数据库:

enter image description here

我想创建一个如果用户同时分配腿部和手臂运动的地方,数据库将在一行中显示腿部和手臂运动。但是现在当我将它们都插入在一起时,数据库中的数据将位于两个不同的行中。

.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>

0 个答案:

没有答案