Java - sintaxis...help!!!!

 
Vista:

sintaxis...help!!!!

Publicado por erick (3 intervenciones) el 20/07/2006 20:33:57
quiero conectarme a una base de datos pero me marca error en el nombre de la base de datos: este es mi codigo..

package whwrapper;

import java.io.*;
import java.net.URL;
import java.sql.*;
import java.util.Properties;
import java.util.Vector;

public class DBConnect {

public Statement stmt;//estaments
public Connection con;//conector
public String excpt, iJDBC, iURL;
private boolean dbg = false;

/**
* connect to the Database:
* @host = a String that contains the DB-Server-hostname e.g. gotzenwil.eidberg.ch
* @user = a String that represents the user as it is in the grant-table of the db
* @password = a String that contains the users password: Attention: not encrypted,
* is going in plaintext over the network, (Yes, there is some room for improvement)
* @database = the name of the database you want to connect to
*
* the JDBC-Driver stuff is in a property-file stored in the users -home-dir
* named: t_connect.props
*/

public DBConnect (String host, String user, String password, String database) {

Properties prop = new Properties();


try {

FileInputStream fip = new FileInputStream( "C:/Documents and Settings/Administrador/Mis documentos/whes2/dbconect.props" );
prop.load(fip);

System.out.println("importa propiedades");
}
catch (Exception ioex) {
System.out.println("db_connect: can not load " + ioex + "\n using standard values");
//prop.put("JDBCdriver","org.gjt.mm.mysql.Driver");
//prop.put("JDBCurl","jdbc:mysql://");
//prop.put("DatabasePort","80");
//prop.put("usePassword","yes");
//prop.put("DebugMode","off");
}

excpt = null;
String url = "";
int po = 0;

try
{

Class.forName(prop.getProperty("JDBCdriver"));

url = prop.getProperty("JDBCurl") ;

iJDBC = prop.getProperty("JDBCdriver");
iURL = prop.getProperty("JDBCurl") ;


// For non networked stuff set Port to 0
try {
po = Integer.parseInt(prop.getProperty("DatabasePort"));

System.out.println(po);
} catch (NumberFormatException nfe) {
po = 0;
if ( dbg ) dbgMessage("not networked, no Port in use");
}

if ( dbg ) dbgMessage(url+" "+iJDBC+" "+iURL+" "+prop.getProperty("DatabasePort")+" "+database+" "+host+" "+user+" "+password);

if (po > 0 ) {
if ( prop.getProperty("JDBCdriver").startsWith("mysql") ) {
url = url + user + "/" + password + "@" + host + ":" + prop.getProperty("DatabasePort") + ":" + database;
iURL = url;

} else {
url = url + host + ":" + prop.getProperty("DatabasePort") + "/" + database;
iURL = url;
}
} else {
url = url + database;
iURL = url;
}

if ( dbg ) dbgMessage("URL: " + url);

Properties p = new Properties();

if ( ! prop.getProperty("JDBCdriver").startsWith("mysql") ) {

p.put("user",user);
if ( prop.getProperty("usePassword").equalsIgnoreCase("yes") ) {
p.put("password", password);
}

con = DriverManager.getConnection(url,p);
} else {
con = DriverManager.getConnection(url);
}

}
catch (Exception e) {
excpt = "Exception while opening "+ database + " on " + host + " : " + e.getMessage() + "\n" +
"url: " + url;
if ( dbg ) dbgMessage(excpt);

}

}

public void close() {

excpt = null;
try
{
//dbgMessage("closing ...");
//stmt.close();
con.close();
}
catch (Exception e) {
excpt = "Exception while closing database: " + e.getMessage().toString();
if ( dbg ) dbgMessage(excpt);
}
}

public String getError() {

return excpt;

}

private void dbgMessage( String msg ) { System.out.println(msg); }

}

como debo de escribir la sintaxis del nombre de mi base de datos
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder