java - Left JOIN issuesdevices AS sm ON sd.DeviceID = sm.DeviceID' 在第 1 行

标签 java sql jdbc mariadb

我想从两个表中获取数据。

表一 deviceadd 具有以下列

DeviceID (primary key), DeviceName, SerialNumber, ModelNumber, Make

另一个表issuedevices有这些列:

Device_ID (Unique), Employee_id, Employee_Name, Employee_Ext, Issue_Date

我收到此错误:

java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Left JOIN issuedevices AS sm ON sd.DeviceID = sm.DeviceID' at line 1

PreparedStatement ps=con.prepareStatement("Selectsd.DeviceID,sd.DeviceName,sd.SerialNumber,sd.ModelNumber,sd.Make,sm.DeviceID,sm.Employee_Name,sm.Employee_Ext,sm.Issue_Date From deviceadd AS sd,Left JOIN issuedevices AS sm ON sd.DeviceID = sm.DeviceID");

        ResultSet rs=ps.executeQuery();

        ResultSetMetaData rsmd=rs.getMetaData();
        int cols=rsmd.getColumnCount();
        column=new String[cols];
        for(int i=1;i<=cols;i++)
        {
            column[i-1]=rsmd.getColumnName(i);
        }

        rs.last();
        int rows=rs.getRow();
        rs.beforeFirst();

        data=new String[rows][cols];
        int count=0;
        while(rs.next()){
            for(int i=1;i<=cols;i++)
            {
                data[count][i-1]=rs.getString(i);
            }
            count++;
        }
        con.close();
    }catch(Exception e){System.out.println(e);}

    table = new JTable(data,column);
    JScrollPane sp=new JScrollPane(table);

    contentPane.add(sp, BorderLayout.CENTER);

最佳答案

一个可能的原因是这里没有空间:

Selectsd.DeviceID

应该是

Select sd.DeviceID

此外,这里不应该有逗号:

sd,Left JOIN

关于java - Left JOIN issuesdevices AS sm ON sd.DeviceID = sm.DeviceID' 在第 1 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56320514/

相关文章:

java - 有没有人在 Tomcat 中成功使用 JBoss AOP?

java - 停止在页面重新加载时将表单的先前数据提交到jsp中的数据库

java - 错误 java.sql.SQLException : ORA-01722: invalid number while running a Prepared Statement to alter a Sequence

java - 本地 H2 服务器 + hibernate : existing database is not visible

mysql - 无法在 Pehtaho 报表设计器中通过 JDBC 连接到数据库

java - JHipster 错误 : Could not find or load main class org. apache.maven.wrapper.MavenWrapperMain

java - 我需要数据结构来有效处理日期

java - DataOutputStream.write(int b) 不写入

mysql - 如何三重连接表以查找和查找匹配两个事物的条目?

sql - 跟踪表中的更改