Problemer
Jeg får følgende fejl når jeg forsøger at oprette forbindelse til min mssql-database via java:[Microsoft][ODBC Driver Manager] Invalid string or buffer length
Filen jeg bruger til at oprette forbindelsen, kan ses her:
package DBLayer;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
/**
*
* @author Kasper
*/
public class DBConnection {
//constans used to get access to the database
//SQL Server
private static final String driver = "jdbc:odbc:";
//MySql
//private static final String driver = "jdbc:mysql://localhost:3306/";
private static final String databaseName = "Westernstyle";
//SQL Server
private static final String userName = "";
private static final String password = "";
//MySql password and username
//private static final String userName = "root";
//private static final String password = "fisk";
private DatabaseMetaData dma;
private static Connection con;
// an instance of the class is generetated
private static DBConnection instance = null;
// the constructor is private to ensure that only one object of this class is createt
private DBConnection()
{
String url = driver + databaseName;
try{
//load af driver
//SQL Server
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// mySQL
// Class.forName("org.gjt.mm.mysql.Driver");
}
catch(Exception e){
System.out.println("Can not find the driver");
System.out.println(e.getMessage());
}//end catch
try{
//connection to the database
con = DriverManager.getConnection(url, userName,password);
//set autocommit
con.setAutoCommit(true);
dma = con.getMetaData(); // get meta data
System.out.println("Connection to " + dma.getURL());
System.out.println("Driver " + dma.getDriverName());
System.out.println("Database product name " + dma.getDatabaseProductName());
}//end try
catch(Exception e){
System.out.println("Problems with the connection to the database");
System.out.println(e.getMessage());
}//end catch
}//end constructor
//closeDb: closes the connection to the database
public static void closeConnection()
{
try{
con.close();
System.out.println("The connection is closed");
}
catch (Exception e){
System.out.println("Error trying to close the database " + e.getMessage());
}
}//end closeDB
//getDBcon: Get-metode, returnerer forbindelsen til databasen
public Connection getDBcon()
{
return con;
}
//this method is used to get the instance of the connection
public static DBConnection getInstance()
{
if (instance == null)
{
instance = new DBConnection();
}
return instance;
}
}//end DbConnection
Så vidt jeg kan se, drejer det sig om, at jeg forsøger at indsætte en værdi der ikke passer til den tabel jeg forsøger at sætte det ind i, men jeg kan ikke se hvor jeg sætter noget ind i databasen.