no

How to Connect Msaccess Database Using Java

The method is almost similar to my previous code, and like that it's better to explain it by code: private static Connection getConnec...

The method is almost similar to my previous code, and like that it's better to explain it by code:

private static Connection getConnection() {
 String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
    String url = "jdbc:odbc:anime"; //anime is the database
    String username = "ipieluser"; //leave blank if none
    String password = "ipielpassword"; //leave blank if none
    try {
  Class.forName(driver);
 } catch (ClassNotFoundException e) {
  e.printStackTrace();
 }
    try {
  return DriverManager.getConnection(url, username, password);
 } catch (SQLException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
 }
 return null;
}

How to call:
public static void main(String args[]) {
 try {
  Connection conn = getConnection();
     Statement st = conn.createStatement();
     st = conn.createStatement();
     ResultSet rs = st.executeQuery("SELECT * FROM localTable");     
     
  //get and displays the number of columns
     ResultSetMetaData rsMetaData = rs.getMetaData();
  int numberOfColumns = rsMetaData.getColumnCount();
     System.out.println("resultSet MetaData column Count=" + numberOfColumns);
 
     st.close();
     conn.close();
 } catch(Exception e) {
  System.out.println(e.getMessage());
 }
}

Related

java-persistence 5907383963465564471

Post a Comment Default Comments

item