Registros en java

Me ingresa 10 veces el registro al igual que los mismos codigo que introduzco en el campo de la tabla
¿Por que puede ser?
¿Me dices que puedo hacer para solucionarlo?
import java.sql.*;
public class registro_usuario {
static String login = "root";
static String password = "";
static String url = "jdbc:mysql://localhost/Acceso";
public static void mai(String ... Args) throws Exception
{
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection(url,login,password);
if (conn != null)
{
int rows_updated = 0;
PreparedStatement stmt1 = conn.prepareStatement("INSERT INTO profesores (nombre ,clave) "
+ "VALUES (?,?)");
stmt1.setString(1,"Pedro"); // Nombre
int [][] A= new int[2][5];
for(int i=0;i<A.length;i++)
{ for(int j=0;j<A[0].length;j++)
{
A[j]=(int)(Math.random()*1000);
}
}
for(int i=0;i<A.length;i++)
{ for(int j=0;j<A[0].length;j++)
{
String matrizComoString = toString( A);
stmt1.setString(2,matrizComoString); // Clave
rows_updated = stmt1.executeUpdate();
}
}}
}
catch(SQLException ex) {
System.out.println(ex);
}
catch(ClassNotFoundException ex) {
System.out.println(ex); }
}
public static void ma( String ... Args ) {
String matrizComoString = toString( m );
System.out.println( matrizComoString );
int [][] resort = new int[3][3];
fromString( matrizComoString, resort );
System.out.println( toString( resort) );
}
public static String toString( int [][] m ) {
StringBuilder sb = new StringBuilder();
for( int i = 0 ; i < m.length ; i++ ) {
for( int j = 0 ; j < m.length ; j++ ) {
sb.append( m[j] );
sb.append( "," );
}
}
return sb.toString();
}
public static void fromString( String matrizComoString, int [][] resort ) {
int i = 0;
int j = 0;
for( String numero : matrizComoString.split(",")) {
System.out.printf( "(%d,%d) = %s%n",i,j,numero );
resort[j++] = Integer.parseInt( numero );
if( j > 2 ) {
i++;
j = 0;
}
}
}}

1 Respuesta

Respuesta
1
No termino de entender muy bien el problema, pero tal vez deberías revisar esta línea:
A[j]=(int)(Math.random()*1000);
Si la matriz es de dos dimensiones tal vez debas decirle cuál es la fila a la que te refieres y no sólo la columna, ¿no?
Si esto no resuelve el problema, por favor, explica más cláramente qué es lo que sucede.
En caso de darte salida al problema.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas