Hi, I am vee and I am trying to create a Natural Language search engine based on LSI. I am stuck up and I would be really glad if I could use some help.

I have a two-dimensional array which is full of numbers. I want to transfer the contents of the array in an SQL database.
Example - >
Array(A[2][3]) = 3 4 6
7 8 2

So, My SQL table should have :
c1 c2 c3
r1 3 4 6
r2 7 8 2

Please let me know if you have any further questions. Thank you.

So I was thinking of using 2 for loops to create two SQL columns, but I am not sure whether I will be able to. And moreover, SQL statements are written in double quotes, So, I am not sure whether they will read i and j (2D looping variables).

Edited 5 Years Ago by freaky_sxyvs: re- formatting

For the create statement you need only know how deep the second dimension is (i.e. the array[0].length) then use a loop to use String concatenation (or better two StringBuilders, but I don't know if you're ready for those) to create the sql for a CREATE TABLE statement and an INSERT statement (with the INSERT sql being usable in a PreparedStaatement, see the API docs and JDBC Tutorials for more information on PreparedStatement).

Now, using that information (and hopefully you know sql well enough to know how to make CREATE TABLE and INSERT sql statements) give it a try and the post that code here and we will help you to correct it (if it doesn't "work", but give us complete information as to the exception/compiler message(s)).

hey freaky you for example if you have

preparedstatment ps = new preparestatment("insert into student values( "x" , "y" )");

x and y here are known and you enters by your hand but if your variable doesn't have a constant value so you can you use

preparedstatment ps = new preparestatment("insert into student values(? , ?)");
ps.setString(1 , "Ahmed"); // if your variables are Strings
ps.setString(2 , "sara"); // you can also use ps.setint() as well

hey freaky you for example if you have

No idea what you mean with that.

preparedstatment ps = new preparestatment("insert into student values( "x" , "y" )");

For one, you forgot the pluses in that statement (as well as mentioning that single quotes will need to be included for non-numeric values and to_date functions for dates), for another, if the statement is complete (i.e. there are no ?'s), and is not going to be used repeatedly in the same DB session, then use Statement not PreparedStatement (there is no reason to allow even the minimal overhead that PreparedStatement needs when you don't need to). And to make it clear to the OP, do not do it this way if these values come from anywhere other than hard-coded values or you run a large risk of sporadic SQL syntax errors and/or (intentional or unintentional) SQL Injection attacks.

Edit: Besides the fact that don't create either Statements or PreparedStatements with a call to constructor. Those are interfaces they don't have constructors.

Edited 5 Years Ago by masijade: n/a

firstly yeah your are right about my double quotes

secondly i didn't get your point about the preparedstatement so please try to make it more clearer or send a doc. about it because i really don't understand the difference between then (also i get used to it so i didn't try to change)

thirdly i used the (?s) when i didn't know the values to be entered in the database (i will get them from the user) , also i can't get your point about it

This article has been dead for over six months. Start a new discussion instead.