我想从两个表中获取数据。
表一 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/