I am studying Java and I have an error.
I want to work with the mysql database
It's a code.
CarDAO.java
package jv16;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;
//DAO : 데이터 처리 객체
public class CarDAO {
public Connection dbconn(){
Connection conn = null;
try {
FileInputStream fis = new FileInputStream("d:\\db.prop");
Properties prop = new Properties();
prop.load(fis);
String url = prop.getProperty("url");
String id = prop.getProperty("id");
String password = prop.getProperty("password");
conn = DriverManager.getConnection(url,id,password);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
}
I've been looking for a lot of stackoverflow articles to solve the problem,
but I have not been able to fix it.
This is the code in the db.prop file.
url=jdbc:mysql://localhost/java
driver=com.mysql.jdbc.Driver
id=java
password=*******
It's the error code that Eclipse shows.
com.mysql.jdbc.Driver
null
java
********
java.sql.SQLException: The url cannot be null
at java.sql.DriverManager.getConnection(DriverManager.java:649)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at jv16.SqlInsertTest.main(SqlInsertTest.java:24)
This is the 24th line code in SqlInsertTest.java.
conn = DriverManager.getConnection(url,id,password);