java.sql.SQLSyntaxErrorException:语法错误:在第1行第15列遇到“Book”
package javaapplication2;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
//jdbc:derby://localhost:1527/LMS
class abc {
public abc() throws SQLException{
//ConnectionURL, username and password should be specified in getConnection()
//ConnectionURL, username and password should be specified in getConnection()
try {String url = "jdbc:derby://localhost:1527/LMS";
Connection conn = DriverManager.getConnection(url,"zain","12345");
System.out.println("Connected! ");
String sql = "SELECT * FROM BOOK";`enter code here`
Statement st = conn.createStatement();
ResultSet rs=st.executeQuery(sql);
String x;
while(rs.next()){
System.out.println(rs.getString("Password"));
}
}
catch (SQLException ex) {
System.out.println(ex);
}
}
}
我得到这个任何导致?我正在尝试这件事几个小时,并没有得到任何领先:/ PLZ的帮助。我正在制作一个图书馆管理系统,并为其制作了一个专栏书籍,并试图从中获取数据。java.sql.SQLSyntaxErrorException:语法错误:在第1行第15列遇到“Book”
德比是一个棘手的野兽。 这里有一个数据retreivale和准备用于插入的工作示例为一个JTable
public static final String DRIVER= "org.apache.derby.jdbc.EmbeddedDriver";
public static final String JDBC_URL = "jdbc:derby://localhost:1527/LMS";
private void GetData()throws SQLException
{
Connection connection=DriverManager.getConnection(JDBC_URL,"zain","12345");
ResultSet result = null;
String sql2 = "select * from book";
PreparedStatement ps1 = connection.prepareStatement(sql2, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY) ;
result = ps1.executeQuery();
// get number of rows
result.last();
int numRows = result.getRow();
result.first();
//Get metadata object for result
ResultSetMetaData meta = result.getMetaData();
// create an arry of string for the colum names
colNames = new String[meta.getColumnCount()];
// store column names in the new col names array
for(int i = 0; i< meta.getColumnCount(); i++)
{
//get column name
colNames[i] = meta.getColumnLabel(i+1);
}
// create 2 d string array for table data
tableData = new String [numRows][meta.getColumnCount()];
// store columns in the data
for (int row = 0 ; row < numRows; row++)
{
for (int col = 0; col < meta.getColumnCount(); col++)
{
tableData[row][col]= result.getString(col + 1);
}
result.next();
}
// close statement
ps1.close();
connection.close();
} // end get data
要插入AA桂...
table = new JTable(tableData,colNames);
JScrollPane scrollPane = new JScrollPane(table);
你为什么说“是棘手的野兽”?全部在主流JDBC –
我可以使用Oracles SQL开发人员零问题。为了在德比数据库中找到我想要的数据而让java在我的生活中失去了日子 –
为了在java中使用德比,你必须学习他们在我的Java大学课程中没有教授的配置。夫妇,与谷歌搜索如何在Java中使用德比和你充斥着旧信息已经过时,只是普通不起作用 –
我假设本书是你的表不是列 –
是你确定你知道哪条语句给你错误?您的粘贴代码显示'BOOK',您的异常消息显示为'Book'。也许你运行的代码比你想象的要多。确保通过遵循http://wiki.apache.org/db-derby/UnwindExceptionChain获取完整的异常信息。另外,使用-Dderby.language.logStatementText = true运行你的程序,并查看你的derby.log,看看*完全正确*传递给数据库的SQL是什么。 –