Results 1 to 2 of 2
Thread: Properties file not found
- 08-08-2011, 08:08 PM #1
Member
- Join Date
- Jul 2011
- Location
- Norwich, UK
- Posts
- 1
- Rep Power
- 0
Properties file not found
I'm following an online tutorial (MySQL Java tutorial) and I've just created a properties file to manage my mysql credentials. When I try to run the code below I can't a FileNotFoundException on "database.properties". It's located in my src folder so I don't know where the problem is? I'm using Eclipse IDE if that's relevant.
Thanks.
Java Code:import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.Properties; public class MySqlTest { public static void main(String[] args) { Connection con = null; try { con = getConnection(); Statement st = con.createStatement(); ResultSet result = st.executeQuery("SELECT * FROM Authors"); while (result.next()) { System.out.print(result.getInt(1)); System.out.print(": "); System.out.println(result.getString(2)); } con.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } public static Connection getConnection() throws FileNotFoundException, IOException, SQLException { Properties props = new Properties(); FileInputStream in = new FileInputStream("database.properties"); props.load(in); in.close(); String url = props.getProperty("db.url"); String user = props.getProperty("db.user"); String passwd = props.getProperty("db.passwd"); return DriverManager.getConnection(url, user, passwd); } }
- 08-08-2011, 09:30 PM #2
Similar Threads
-
the mp3 file is not working..java.io.IOException: File Not Found......javax.media.NoP
By shruts in forum Java AppletsReplies: 1Last Post: 07-28-2011, 07:50 PM -
ResourceBundleViewResolver properties file
By frenk_castle in forum Web FrameworksReplies: 1Last Post: 04-07-2011, 07:39 PM -
Unable to access velocity.properties file from jar file
By mjwoodford in forum New To JavaReplies: 0Last Post: 10-09-2009, 01:46 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks