Netbeans 访问
Netbeans ucanaccess
conn = Connect.ConnectDB();
String sql = "insert into Ianouarios ("
+"id,"
+"Hmerominia,"
+"Agores,"
+"Pliromes,"
+"Eksoda,"
+ "Zhta,"
+"Metaforika,"
+"Pliromimetafo,"
+"Epitages,"
+"Xondriki,"
+"Noiki,"
+"Plirominoiki)"
+ "values("+a1.getText()+ ",'"+a2.getText()+"','"+a3.getText()+"','"+a4.getText()+"','"+a5.getText()+"','"+a6.getText()+"','"+a7.getText()+"','"+a8.getText()+"','"+a9.getText()+"','"+ a10.getText()+ "','"+a11.getText()+"','"+a12.getText()+"')" ;
try{
pst = conn.prepareStatement(sql);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Saved");
//UpdateJTable();
//conn.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
我有一个 MS 访问数据库,我正在使用 jdbc-odbc 驱动程序更新它。
任何人都可以告诉我如何使用 ucanaccess 驱动程序做同样的事情吗?
我尝试了他们的 ucanaccess 页面示例,但没有成功。
更新:我这样做了:
conn = Connect.ConnectDB();
try{
String sql = "INSERT INTO Synola(id,Hmerominia,Agores,Pliromes,Eksoda,Zhta,Metaforika,Pliromimetafo,Epitages,Xondriki,Noiki,Plirominoiki) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)" ;
/* SimpleDateFormat ddmmyyyyFormat = new SimpleDateFormat("dd/MM/yyyy");
Timestamp ddmmyyyy = new Timestamp(ddmmyyyyFormat.parse(a2.getText()).getTime()); */
// String s=ddmmyyyy.toString();
pst = conn.prepareStatement(sql);
pst.setString(1, a1.getText());
pst.setString(2,a2.getText());
pst.setString(3, a3.getText());
pst.setString(4, a4.getText());
pst.setString(5, a5.getText());
pst.setString(6, a6.getText());
pst.setString(7, a7.getText());
pst.setString(8, a8.getText());
pst.setString(9, a9.getText());
pst.setString(10, a10.getText());
pst.setString(11, a11.getText());
pst.setString(12, a12.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Saved");
//UpdateJTableSynola();
// conn.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
现在的问题是 a2.getText() 字段中的日期,我将其作为 (dd/MM/yyyy) 放入数据库。错误无法解析 date.How 我可以解决这个问题吗?
作为 JDBC-ODBC Bridge has been removed in JDK8, what you can do is to use JDBC along with UCanAccess API 连接到 MSAccess 数据库。
connection = DriverManager
.getConnection("jdbc:ucanaccess:////REMOTE-IP-ADDRESS/shared-folder/TestDB.mdb");
System.out.println("CONNECTION ESTABLISHED....");
这是一个小示例(在 Java 8 中测试),它使用 JDBC/UCanAccess API 连接到远程 MS-Access 数据库。确保您的项目构建路径中有以下 jar。
- commons-lang-2.6.jar
- commons-logging-1.1.1.jar
- hsqldb.jar
- jackcess-2.1.0.jar
- ucanaccess-2.0.9.5.jar
代码:
/**
* Connects to a remote MS-Access DB using JDBC/UCanAccess API.
*/
package miscellaneous;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ConnectRemoteDB {
public static void main(String[] args) {
initializeConnection();
}
/**
* Initializes remote database connection and inserts a record and closes the connection.
*/
private static void initializeConnection() {
System.out.println("Attempting Database Connection...");
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = DriverManager
.getConnection("jdbc:ucanaccess:////REMOTE-IP-ADDRESS/shared-folder/TestDB.mdb");
System.out.println("CONNECTION ESTABLISHED....");
String insertTableSQL = "INSERT INTO Table1" + "(Name) VALUES"
+ "(?)";
preparedStatement = connection.prepareStatement(insertTableSQL);
preparedStatement.setString(1, "Sandeep");
preparedStatement.executeUpdate();
System.out.println("RECORD INSERTED...");
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
System.out.println("CONNECTION CLOSED...");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
conn = Connect.ConnectDB();
String sql = "insert into Ianouarios ("
+"id,"
+"Hmerominia,"
+"Agores,"
+"Pliromes,"
+"Eksoda,"
+ "Zhta,"
+"Metaforika,"
+"Pliromimetafo,"
+"Epitages,"
+"Xondriki,"
+"Noiki,"
+"Plirominoiki)"
+ "values("+a1.getText()+ ",'"+a2.getText()+"','"+a3.getText()+"','"+a4.getText()+"','"+a5.getText()+"','"+a6.getText()+"','"+a7.getText()+"','"+a8.getText()+"','"+a9.getText()+"','"+ a10.getText()+ "','"+a11.getText()+"','"+a12.getText()+"')" ;
try{
pst = conn.prepareStatement(sql);
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Saved");
//UpdateJTable();
//conn.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
我有一个 MS 访问数据库,我正在使用 jdbc-odbc 驱动程序更新它。
任何人都可以告诉我如何使用 ucanaccess 驱动程序做同样的事情吗?
我尝试了他们的 ucanaccess 页面示例,但没有成功。
更新:我这样做了:
conn = Connect.ConnectDB();
try{
String sql = "INSERT INTO Synola(id,Hmerominia,Agores,Pliromes,Eksoda,Zhta,Metaforika,Pliromimetafo,Epitages,Xondriki,Noiki,Plirominoiki) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)" ;
/* SimpleDateFormat ddmmyyyyFormat = new SimpleDateFormat("dd/MM/yyyy");
Timestamp ddmmyyyy = new Timestamp(ddmmyyyyFormat.parse(a2.getText()).getTime()); */
// String s=ddmmyyyy.toString();
pst = conn.prepareStatement(sql);
pst.setString(1, a1.getText());
pst.setString(2,a2.getText());
pst.setString(3, a3.getText());
pst.setString(4, a4.getText());
pst.setString(5, a5.getText());
pst.setString(6, a6.getText());
pst.setString(7, a7.getText());
pst.setString(8, a8.getText());
pst.setString(9, a9.getText());
pst.setString(10, a10.getText());
pst.setString(11, a11.getText());
pst.setString(12, a12.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Saved");
//UpdateJTableSynola();
// conn.close();
}catch(Exception ex){
JOptionPane.showMessageDialog(null, ex);
}
现在的问题是 a2.getText() 字段中的日期,我将其作为 (dd/MM/yyyy) 放入数据库。错误无法解析 date.How 我可以解决这个问题吗?
作为 JDBC-ODBC Bridge has been removed in JDK8, what you can do is to use JDBC along with UCanAccess API 连接到 MSAccess 数据库。
connection = DriverManager
.getConnection("jdbc:ucanaccess:////REMOTE-IP-ADDRESS/shared-folder/TestDB.mdb");
System.out.println("CONNECTION ESTABLISHED....");
这是一个小示例(在 Java 8 中测试),它使用 JDBC/UCanAccess API 连接到远程 MS-Access 数据库。确保您的项目构建路径中有以下 jar。
- commons-lang-2.6.jar
- commons-logging-1.1.1.jar
- hsqldb.jar
- jackcess-2.1.0.jar
- ucanaccess-2.0.9.5.jar
代码:
/**
* Connects to a remote MS-Access DB using JDBC/UCanAccess API.
*/
package miscellaneous;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ConnectRemoteDB {
public static void main(String[] args) {
initializeConnection();
}
/**
* Initializes remote database connection and inserts a record and closes the connection.
*/
private static void initializeConnection() {
System.out.println("Attempting Database Connection...");
Connection connection = null;
PreparedStatement preparedStatement = null;
try {
connection = DriverManager
.getConnection("jdbc:ucanaccess:////REMOTE-IP-ADDRESS/shared-folder/TestDB.mdb");
System.out.println("CONNECTION ESTABLISHED....");
String insertTableSQL = "INSERT INTO Table1" + "(Name) VALUES"
+ "(?)";
preparedStatement = connection.prepareStatement(insertTableSQL);
preparedStatement.setString(1, "Sandeep");
preparedStatement.executeUpdate();
System.out.println("RECORD INSERTED...");
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
connection.close();
System.out.println("CONNECTION CLOSED...");
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}