Reputation: 3
I'm currently studying this program and I've tried to solve this myself, but it seems that I can't understand what went wrong.
How can I connect it to my database? :)
Here is the my code below:
package payroll.system;
import java.io.IOException;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import javax.swing.JDialog;
import java.io.*;
import java.util.*;
import java.net.*;
public class clsConnection {
String url = "";
String username = "";
String password = "";
public Connection setConnection(Connection conn, String username, String password )
{
try
{
Properties props = new Properties();
String fileName = "MakeDB.ini"; FileInputStream in = new FileInputStream(fileName);
props.load(in);
String drivers = props.getProperty("jdbc.drivers");
if(drivers != null)
System.setProperty("jdbc.drivers", drivers);
url = props.getProperty("jdbc.url");
username = props.getProperty("jdbc.username");
password = props.getProperty("jdbc.password");
conn = DriverManager.getConnection(url,username,password);
}catch(SQLException e)
{
System.err.println("SQl Exception");
e.printStackTrace();
}
catch(IOException e)
{
System.out.println("\nIO Exception");
}
catch (Exception e)
{
System.out.println("\nAnother Error");
}
return conn;
}
}
THIS IS THE ERROR after I compile the program:
SQl Exception
java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6964)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7121)
at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(JdbcOdbc.java:3080)
at sun.jdbc.odbc.JdbcOdbcConnection.initialize(JdbcOdbcConnection.java:323)
at sun.jdbc.odbc.JdbcOdbcDriver.connect(JdbcOdbcDriver.java:174)
Upvotes: 0
Views: 1181