wood burning stoves 2.0*
The moose likes JDBC and the fly likes Collision of Date format between java.sql and SQL Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Reply locked New topic
Author

Collision of Date format between java.sql and SQL Server

rameshmca rk
Greenhorn

Joined: Jan 27, 2007
Posts: 17
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("jdbcdbc: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

*/
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30146
    
150

The above code goes with this other thread. I'll close this one so we can continue discussion in one place.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collision of Date format between java.sql and SQL Server
 
Similar Threads
Swing 1.1(URgent)
blinking tab pane
Acheiving Focus using EnterKey
Scrollbar not working
The INSERT INTO statement contains the following unknown field name: 'OPANo'.