Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Collision of Date format between java.sql and SQL Server

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi,
I have sent my program as follows.So I trust you that I will be satisfied.


//Example program for testing insert statement for ERP

import java.sql.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class InsertGUI1 extends JFrame implements ActionListener
{
JLabel jl1;
JLabel jl2;
JLabel jl3;
JLabel jl4;
JLabel jl5;
JTextField jtf1;
JTextField jtf2;
JTextField jtf3;
JTextField jtf4;
JTextField jtf5;
JLabel result;
JButton jb;
public InsertGUI1(String title)
{
super(title);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container contentpane=getContentPane();
contentpane.setLayout(new FlowLayout());
jl1=new JLabel("Serial No");
jl2=new JLabel("Name");
jl3=new JLabel("Age");
jl4=new JLabel("Designation");
jl5=new JLabel("Date Of Birth");
jtf1=new JTextField(15);
jtf2=new JTextField(15);
jtf3=new JTextField(15);
jtf4=new JTextField(15);
jtf5=new JTextField(15);
result=new JLabel("Result");
jb=new JButton("Save");
contentpane.add(jl1);
contentpane.add(jl2);
contentpane.add(jl3);
contentpane.add(jl4);
contentpane.add(jl5);

contentpane.add(jtf1);
contentpane.add(jtf2);
contentpane.add(jtf3);
contentpane.add(jtf4);
contentpane.add(jtf5);

contentpane.add(result);
contentpane.add(jb);

setVisible(true);
setSize(900,900);
jb.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
if(ae.getSource().equals(jb))
{
String serialno=jtf1.getText();
int intF1=Integer.parseInt(serialno);
String strF2=jtf2.getText();
String age=jtf3.getText();
int intF3=Integer.parseInt(age);
String strF4=jtf4.getText();
String strF5=jtf5.getText();
Date dtF5=Date.valueOf(strF5);


Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:TestSQL");
PreparedStatement ps=con.prepareStatement("insert into profile1 values(?,?,?,?,?)");
ps.setInt(1,intF1);
ps.setString(2,strF2);
ps.setInt(3,intF3);
ps.setString(4,strF4);
ps.setDate(5,dtF5);

ps.executeUpdate();

ps.close();
con.close();

result.setText("Record has been inserted");
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public static void main(String[] args)
{
InsertGUI1 insertGUI1=new InsertGUI1("Test Frame for insert statement");
}

}

/* I gave inputs as following for SQL table

type length
serialno : 145 numeric 9
name : Ramesh RK varchar 50
age : 34 int 4
designation : Programmer varchar 50
Date Of Birth : 1973-07-31 datetime 8

I got error as

"java.sql.SQLException:

[Microsoft] [ODBC SQL Server Driver] Optional feature not implemented

*/
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
The above code goes with this other thread. I'll close this one so we can continue discussion in one place.
 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic