Note that there are some explanatory texts on larger screens.

plurals
  1. POSQl datatype length
    primarykey
    data
    text
    <pre><code>package drivers; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; public class Main implements ActionListener { private JFrame f; private JLabel lb_name,lb_email,lb_address,lb_hourlyrate,lb_startdate,lb_enddate,lb_reason,lb_homeph,lb_cellph,lb_image; private JTextField tx_name,tx_email,tx_address,tx_hourlyrate,tx_startdate,tx_enddate,tx_homeph,tx_cellph; private JButton bt_go,bt_next,bt_image; private JTextArea txf_reason; private ImageIcon ic; private JPanel p; public String s=""; public Main() { f=new JFrame(); lb_name=new JLabel("Name"); lb_email=new JLabel("E-mail"); lb_address=new JLabel("Address"); lb_hourlyrate=new JLabel("Hourly Rate"); lb_startdate=new JLabel("Starting Date"); lb_enddate=new JLabel("Enddate"); lb_reason=new JLabel("Reason of Quiting"); lb_homeph=new JLabel("Home Phone"); lb_cellph=new JLabel("Cell Phone"); tx_name=new JTextField(); tx_email=new JTextField(); tx_address=new JTextField(); tx_hourlyrate=new JTextField(); tx_startdate=new JTextField(); tx_enddate=new JTextField(); txf_reason=new JTextArea(); tx_homeph=new JTextField(); tx_cellph=new JTextField(); bt_image=new JButton("Browse"); bt_image.addActionListener(this); bt_go=new JButton("Go"); bt_go.addActionListener(this); bt_next=new JButton("Next"); bt_next.addActionListener(this); ic =new ImageIcon(s); lb_image=new JLabel(); lb_image.setIcon(ic); p=new JPanel(); p.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(255,255,255), 1, true)); } public void launch() { f.setLayout(null); f.setSize(630,470); f.add(lb_name); f.add(lb_email); f.add(lb_address); f.add(lb_hourlyrate); f.add(lb_startdate); f.add(lb_enddate); f.add(lb_reason); f.add(lb_homeph); f.add(lb_cellph); f.add(tx_name); f.add(tx_email); f.add(tx_address); f.add(tx_hourlyrate); f.add(tx_startdate); f.add(tx_enddate); f.add(txf_reason); f.add(tx_homeph); f.add(tx_cellph); f.add(bt_go); f.add(bt_next); f.add(p); p.add(lb_image); p.setBackground(Color.BLACK); lb_name.setBounds(20,30,50,30); tx_name.setBounds(60,30,150,30); bt_go.setBounds(270,30,60,30); lb_email.setBounds(20,110,40,30); tx_email.setBounds(130,113,200,25); lb_address.setBounds(20,140,50,30); tx_address.setBounds(130,143,200,25); lb_hourlyrate.setBounds(20,170,70,30); tx_hourlyrate.setBounds(130,173,60,25); lb_startdate.setBounds(20,200,80,30); tx_startdate.setBounds(130,203,150,25); lb_enddate.setBounds(20,230,80,30); tx_enddate.setBounds(130,233,150,25); lb_homeph.setBounds(20,260,80,30); tx_homeph.setBounds(130,263,100,25); lb_cellph.setBounds(20,290,80,30); tx_cellph.setBounds(130,293,100,25); lb_reason.setBounds(20,320,100,30); txf_reason.setBounds(130,323,200,70); bt_next.setBounds(400,380,60,40); p.setBounds(350,100,220,240); tx_email.setEditable(false); tx_address.setEditable(false); tx_hourlyrate.setEditable(false); tx_startdate.setEditable(false); tx_enddate.setEditable(false); tx_homeph.setEditable(false); tx_cellph.setEditable(false); txf_reason.setEditable(false); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String[] args) { Main m=new Main(); m.launch(); } public void actionPerformed(ActionEvent e) { if(e.getSource().equals(bt_go)) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con =DriverManager.getConnection("jdbc:odbc:project","sa","123456"); String s=tx_name.getText(); Statement stmt= con.createStatement(); ResultSet rs=stmt.executeQuery("SELECT name,address,email,startdate,enddate,reason,homeph,cellph,hourlyrate,image FROM driver"); while(rs.next()) { if(s.equals(rs.getString(1))) { tx_address.setText(rs.getString(2)); tx_email.setText(rs.getString(3)); tx_startdate.setText(rs.getString(4)); tx_enddate.setText(rs.getString(5)); txf_reason.setText(rs.getString(6)); tx_homeph.setText(Integer.toString(rs.getInt(7))); tx_cellph.setText(Integer.toString(rs.getInt(8))); tx_hourlyrate.setText(Integer.toString(rs.getInt(9))); s=rs.getString(10); ic=new ImageIcon(s); lb_image.setIcon(ic); lb_image.setBounds(350,100,200,200); break; } } } catch(Exception ex) { JOptionPane.showConfirmDialog(f,ex); } } else if(e.getSource().equals(bt_next)) { enter en=new enter(); en.launch(); f.hide(); } else if(e.getSource().equals(bt_image)) { String s; JFileChooser jfc = new JFileChooser(); jfc.showDialog(jfc, "Choose an image file"); s = jfc.getSelectedFile().getAbsolutePath(); imagePath.setText(s); } } } </code></pre> <p>i am searching a name from database and displaying it's information on the frame on the basis of name entered so and there's also a frame which is entering the values to the database. i took varhcar(10) as datatype of name. for e.g. if i enter the rahul in name then it is stored as rahul with 5 spaces after it('rahul ').so when i search the database through rahul name it won't display the data until i enter 5 spaces after it. which datatype should i use so as to have length same as that of length of name typed???</p> <p>This is my SQL insert code</p> <pre><code>INSERT INTO [project].[dbo].[driver] ([Name] ,[Address] ,[Email] ,[Hourlyrate] ,[Homeph] ,[Cellph] ,[Startdate] ,[Enddate] ,[Reason] ,[Image]) VALUES (&lt;Name, varchar(20),&gt; ,&lt;Address, varchar(50),&gt; ,&lt;Email, varchar(25),&gt; ,&lt;Hourlyrate, int,&gt; ,&lt;Homeph, bigint,&gt; ,&lt;Cellph, bigint,&gt; ,&lt;Startdate, varchar(30),&gt; ,&lt;Enddate, varchar(30),&gt; ,&lt;Reason, varchar(50),&gt; ,&lt;Image, varchar(200),&gt;) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload