Trying to connect to MS Access

I'm trying to connect to MS access and keep getting the following error:
No description
No description
No description
13 Replies
JavaBot
JavaBot7d ago
This post has been reserved for your question.
Hey @rainycaptain! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Kyo-chan
Kyo-chan7d ago
You're not supposed to just guess the URL. Lookup examples
rainycaptain
rainycaptainOP7d ago
I fixed this error, I'm experiencing another one. Is it okay for me to send it here or should I make a new help post?
Kyo-chan
Kyo-chan7d ago
If the title still corresponds it should be fine here
rainycaptain
rainycaptainOP7d ago
It's happening whenever I try to access whats inside a table in the database
Kyo-chan
Kyo-chan7d ago
sounds like it corresponds to the title. Can't claim to be connected if you can't access any table
rainycaptain
rainycaptainOP7d ago
package Database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class mark {
public static void main(String[] args) {
// Correct JDBC URL format for UCanAccess
String dataBaseURL = "jdbc:ucanaccess:
StudentMarkDatabase\\src\\Database\\Marks Database.accdb";

try {
// Register the JDBC driver
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

// Establish the connection
Connection conn = DriverManager.getConnection(dataBaseURL);

// Create a statement
Statement statement = conn.createStatement();

// Execute the query
String query = "SELECT * FROM tblStudents"; // Ensure correct table name case sensitivity
ResultSet resultSet = statement.executeQuery(query);

// Process the result set
while (resultSet.next()) {
int stuID = resultSet.getInt("StuID");
String firstName = resultSet.getString("FirstName");
String lastName = resultSet.getString("LastName");
String userName = resultSet.getString("UserName");
String password = resultSet.getString("Password");
String dob = resultSet.getString("DOB");

System.out.println("StuID: " + stuID + ", FirstName: " + firstName + ", LastName: " + lastName +
", UserName: " + userName + ", Password: " + password + ", DOB: " + dob);
}

// Close the resources
resultSet.close();
statement.close();
conn.close();

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
package Database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class mark {
public static void main(String[] args) {
// Correct JDBC URL format for UCanAccess
String dataBaseURL = "jdbc:ucanaccess:
StudentMarkDatabase\\src\\Database\\Marks Database.accdb";

try {
// Register the JDBC driver
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

// Establish the connection
Connection conn = DriverManager.getConnection(dataBaseURL);

// Create a statement
Statement statement = conn.createStatement();

// Execute the query
String query = "SELECT * FROM tblStudents"; // Ensure correct table name case sensitivity
ResultSet resultSet = statement.executeQuery(query);

// Process the result set
while (resultSet.next()) {
int stuID = resultSet.getInt("StuID");
String firstName = resultSet.getString("FirstName");
String lastName = resultSet.getString("LastName");
String userName = resultSet.getString("UserName");
String password = resultSet.getString("Password");
String dob = resultSet.getString("DOB");

System.out.println("StuID: " + stuID + ", FirstName: " + firstName + ", LastName: " + lastName +
", UserName: " + userName + ", Password: " + password + ", DOB: " + dob);
}

// Close the resources
resultSet.close();
statement.close();
conn.close();

} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
This is the code^
rainycaptain
rainycaptainOP7d ago
explorer
No description
rainycaptain
rainycaptainOP7d ago
error
No description
rainycaptain
rainycaptainOP7d ago
table^
rainycaptain
rainycaptainOP7d ago
No description
Kyo-chan
Kyo-chan7d ago
I am personally unable to help with Access use, but it is possible that someone else could
JavaBot
JavaBot7d ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.

Did you find this page helpful?