I am new to write sql using java. I can create the tables like this:
String queryCreateBookTable = "create table Book (" +
"isbn char(13) not null," +
"author char(30)," +
"title char(30)," +
"subject char(30)," +
"primary key(isbn))";
And I want to insert some rows from a given array which contains many rows. So I tried this code and it isn't working. How can I fix it without duplicate of primary key and null situation?
public int insertBook(Book[] books)
{
int result = 0;
int art=0;
String query = null;
String[] depo=null;
while(books[art].getIsbn().length() == 13 )
{
if(art==0)
{
depo[0]=books[0].getIsbn();
}
for(int i=0;i<art;i++)
{
if(books[art].getIsbn() ==depo[i])
result++;
else
result=0;
}
if(result==0)
{
query= "insert into Book values ('" +
books[art].getIsbn()+ "','" +
books[art].getAuthor() + "','" +
books[art].getTitle() + "','" +
books[art].getSubject() + "')";
}
}
}