Generate Randon Number With JSP

Hi,I need to generate a random Number with JSP and insert it into my mysql database as an id number? Any Idea how can I do it? please
[147 byte] By [A-Uka] at [2007-10-2 16:54:11]
# 1
you should not use random numbers.. but instead use a sequence.. random numbers cannot be unique.. you can generate a random number now but in the future it can be regenerated again. ask your DBA to make scipt for you to have an auto increment on your table
jgalacambraa at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
thanks for replying, I know what you mean, but I need to do it with JSP, I know it might not be uniqe and I have to check with MySql DB every time to check if num exist or not, and I know it sound stupid, but thats the way it has to be done!!!
A-Uka at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

i hope this helps:

<%

double x = Math.random();

System.out.println("Generated random number: "+x);

String randomNum = x+"";

randomNum = randomNum.substring(2,10);

System.out.println("Generated 8 digit id number: "+Integer.parseInt(randomNum));

%>

jgalacambraa at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Thank you very much,

How can I add X into my database,,,using the following code:

<%String a = request.getParameter("xx");

...

String queryText = "insert into xxxx values(\"\",\"" + request.getParameter("xx") + "\",\""

+ request.getParameter("xx") + "\",\"" + request.getParameter("xx") + "\",\""

+ request.getParameter("xx") + "\",\"" + request.getParameter("x") + "\",\""

+ request.getParameter("xx") + "\")";%>

Thanks again for your reply/

A-Uka at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
i cannot help you with the code now but instead read the articles on it: http://java.sun.com/products/jdbc/learning/index.html
jgalacambraa at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
ok, Thank you
A-Uka at 2007-7-13 18:06:29 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...