与MS Acess的jdbc odbc连接 [英] jdbc odbc connectivity with MS Acess
本文介绍了与MS Acess的jdbc odbc连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生我想将选定的jcombo box值添加到ms访问中的特定列?
帮我plzzzzzzzz
i显示代码错误部分??
将另一个值添加到数据库中,但是当我从组合框中选择任何值并尝试保存时,它将不会被保存或在ms访问中显示所选值的值........
感谢先进的..................
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing。*;
public abstract class New_Customer extends JFrame implements ActionListener
{
JTextField textFieldId;
JTextField textFieldName;
JTextField textFieldContactNo;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JLabel l6;
JComboBox组合;
字符串 course [] = { Navakal, SandhyaKal, Pudhari, MidDay , Inqlab, BusinessLine, Mumbai Samachar, Gujraj Samachar, Karnatak Malla, Vartahar , PunyaNagari};
JButton b1;
JButton b2;
PreparedStatement ps;
容器c = getContentPane();
New_Customer()
{
super ( Shree DattaDigambar Samarth);
setBounds( 140 , 250 , 777 , 555 );
c.setLayout(null);
textFieldId = new JTextField();
textFieldName = new JTextField();
textFieldContactNo = new JTextField();
l1 = new JLabel( 新客户条目跨度>);
l2 = new JLabel( 建筑否跨度>);
l3 = new JLabel( 客户名称跨度>);
l4 = new JLabel( 联系号码跨度>);
l5 = new JLabel( Paper 跨度>);
combo = new JComboBox(课程);
l1.setBounds( 10 , 10 , 340 , 20 );
l2.setBounds( 10 , 20 , 140 , 70 );
l3.setBounds( 110 , 20 , 140 , 70 );
l4.setBounds( 300 , 50 , 140 , 20 );
l5.setBounds( 400 , 50 , 140 , 20 );
textFieldId.setBounds( 10 , 70 , 70 , 20 );
textFieldName.setBounds( 110 , 70 , 180 , 20 );
textFieldContactNo.setBounds( 300 , 70 , 90 , 20 );
combo.setBounds( 400 , 70 , 130 , 20 );
b1 = new JButton( 添加纸张跨度>);
b2 = new JButton( Ok 跨度>);
b1.setBounds( 10 , 100 , 100 , 20 );
b2.setBounds( 10 , 160 , 50 , 20 );
c.add(组合);
c.add(b1);
c.add(b2);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(l4);
c.add(l5);
c.add(textFieldId);
c.add(textFieldName);
c.add(textFieldContactNo);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b1.addActionListener( this );
b2.addActionListener( this );
}
@覆盖
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource()== b2)
{
try
{
Class.forName( sun.jdbc.odbc.JdbcOdbcDriver);
连接con;
con = DriverManager.getConnection( jdbc:odbc:Digambar_Dalvi);
ps = con.prepareStatement( 插入客户(Building_No,Customer_Name,Contact_No,Paper_Name)值(? ?,?,?)跨度>);
ps.setString( 1 ,textFieldId.getText());
ps.setString( 2 ,textFieldName.getText());
ps.setString( 3 ,textFieldContactNo.getText());
error {ps.setString( 4 ,combo.getSelectedValue());
错误ps.executeUpdate();
error}
con.close();
}
catch (例外情况)
{
System.out.println( 错误1: + ex);
}
}
}
public static < span class =code-keyword> void main( String args [])
{
New_Customer v = new New_Customer(){};
}
}
解决方案
请查看是否在管理工具中正确配置了DSN。
sir i want to add selected jcombo box value into ms access in perticular column??
help me plzzzzzzzz
i show in code error part??
the other value is added in to the database but when i selected any value from combobox and try to saved it will not get saved or shown value of selected value in ms access........
thanks in advanced..................
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.swing.*;
public abstract class New_Customer extends JFrame implements ActionListener
{
JTextField textFieldId;
JTextField textFieldName;
JTextField textFieldContactNo;
JLabel l1;
JLabel l2;
JLabel l3;
JLabel l4;
JLabel l5;
JLabel l6;
JComboBox combo;
String course[] = {"Navakal","SandhyaKal","Pudhari","MidDay","Inqlab","BusinessLine","Mumbai Samachar","Gujraj Samachar","Karnatak Malla","Vartahar","PunyaNagari"};
JButton b1;
JButton b2;
PreparedStatement ps;
Container c = getContentPane();
New_Customer()
{
super("Shree DattaDigambar Samarth");
setBounds(140,250,777,555);
c.setLayout(null);
textFieldId = new JTextField();
textFieldName = new JTextField();
textFieldContactNo = new JTextField();
l1 = new JLabel("New Customer Entry");
l2 = new JLabel("Building No");
l3 = new JLabel("Customer Name");
l4 = new JLabel("Contact No");
l5 = new JLabel("Paper");
combo = new JComboBox(course);
l1.setBounds(10,10,340,20);
l2.setBounds(10,20,140,70);
l3.setBounds(110,20,140,70);
l4.setBounds(300,50,140,20);
l5.setBounds(400,50,140,20);
textFieldId.setBounds(10,70,70,20);
textFieldName.setBounds(110,70,180,20);
textFieldContactNo.setBounds(300,70,90,20);
combo.setBounds(400,70,130,20);
b1 = new JButton("Add paper");
b2 = new JButton("Ok");
b1.setBounds(10,100,100,20);
b2.setBounds(10,160,50,20);
c.add(combo);
c.add(b1);
c.add(b2);
c.add(l1);
c.add(l2);
c.add(l3);
c.add(l4);
c.add(l5);
c.add(textFieldId);
c.add(textFieldName);
c.add(textFieldContactNo);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
b1.addActionListener(this);
b2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==b2)
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con;
con = DriverManager.getConnection("jdbc:odbc:Digambar_Dalvi");
ps=con.prepareStatement("insert into Customer(Building_No,Customer_Name,Contact_No,Paper_Name)values(?,?,?,?)");
ps.setString(1,textFieldId.getText());
ps.setString(2,textFieldName.getText());
ps.setString(3,textFieldContactNo.getText());
error{ ps.setString(4,combo.getSelectedValue());
error ps.executeUpdate();
error }
con.close();
}
catch(Exception ex)
{
System.out.println("Error 1:"+ex);
}
}
}
public static void main(String args[])
{
New_Customer v = new New_Customer() {};
}
}
解决方案
please see whether DSN is configured properly in administrative tools.
这篇关于与MS Acess的jdbc odbc连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文