本文介绍了给我洗礼我正在等待答案。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 如何通过JAVA在MS Access后端添加新行。 我正在使用Eclipse工具。解决方案 Java MS Access数据库连接 请按照以下步骤操作: 1)转到开头 - >控制面板 - >管理工具 - >数据源。 2)单击添加按钮,选择驱动程序Microsoft Access Driver(* .mdb)。 3)选择驱动程序后,单击完成按钮。 4)然后给出数据源名称并单击确定按钮。 5)你的DSN将被创建。 6)重启你的编译器并编译你的java代码。 用于插入数据: import java.sql。*; 类 AccessDatabase { public static void main( String [] args){ 尝试 { Class.forName( sun.jdbc.odbc .JdbcOdbcDriver); Connection con = DriverManager.getConnection( jdbc:odbc:student); 语句st = con.createStatement(); 字符串 name = roseindia; 字符串 address = delhi; int i = st.executeUpdate( 插入用户(名称,地址)值(' + name + ',' + address + ')); System.out.println( 添加行); } catch (例外e){ System.out.println(e); } } } 删除数据: import java.sql。*; 类 AccessDatabase { public static void main( String [] args){ 尝试 { Class.forName( sun.jdbc.odbc .JdbcOdbcDriver); Connection con = DriverManager.getConnection( jdbc:odbc:student); 语句st = con.createStatement(); 字符串 name = roseindia; 字符串 address = delhi; int i = st.executeUpdate( 从用户中删除id = 4); System.out.println( 删除行); } catch (例外e){ System.out.println(e); } } } How to add a new row in the MS Access back end through JAVA.I''m using an Eclipse tool. 解决方案 Java MS Access database connectivityFollow these steps:1)Go to the start->Control Panel->Administrative Tools-> data sources.2)Click Add button and select the driver Microsoft Access Driver(*.mdb).3)After selecting the driver, click finish button.4)Then give Data Source Name and click ok button.5)Your DSN will get created.6) Restart your compiler and compile your java code.For Inserting Data:import java.sql.*;class AccessDatabase{ public static void main(String[] args){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:student"); Statement st=con.createStatement(); String name="roseindia"; String address="delhi"; int i=st.executeUpdate("insert into user(name,address) values('"+name+"','"+address+"')"); System.out.println("Row is added"); } catch(Exception e){ System.out.println(e); } }}For deleting data:import java.sql.*;class AccessDatabase{ public static void main(String[] args){ try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:student"); Statement st=con.createStatement(); String name="roseindia"; String address="delhi"; int i=st.executeUpdate("delete from user where id=4"); System.out.println("Row is deleted"); } catch(Exception e){ System.out.println(e); } }} 这篇关于给我洗礼我正在等待答案。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 22:01
查看更多