dcsimg
Data's not inserting into database in NetBeans5.5.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sachin_M
Posted On:   Wednesday, August 1, 2007 01:05 AM

Hi Iam using Netbeans5.5 and MySQL5.0.27 server.I had wrote a piece of code in swing for inserting the value into MySQL server.If the button is pressed the code must be inserted.The code compiles and runs properly,but the value is not inserting into the database properly.I hav made the connection properly.But it's not showing any exception. //some initialization code here public void actionPerformed(ActionEvent ae) { if(ae.getActionCommand().equals("submit")) { try { name=userName.getText(); Class.forName("com.mysql.jdbc.Driver").newInstance(); connection=DriverManager.getCon   More>>

Hi
Iam using Netbeans5.5 and MySQL5.0.27 server.I had wrote a piece of code in swing for inserting the value into MySQL server.If the button is pressed the code must be inserted.The code compiles and runs properly,but the value is not inserting into the database properly.I hav made the connection properly.But it's not showing any exception.

//some initialization code here

public void actionPerformed(ActionEvent ae)


{


if(ae.getActionCommand().equals("submit"))


{



try


{
name=userName.getText();


Class.forName("com.mysql.jdbc.Driver").newInstance();


connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/details?user=root&password=sachin");
statement = connection.createStatement();


sql="insert into details values("+name+")";
count=statement.executeUpdate(sql);



}
catch(Exception e)
{
e.getMessage();
}


finally
{


if(statement!=null)
{


try{
statement.close();
}


catch(Exception e)
{

}



}
if(connection!=null)
{
try
{
connection.close();
}


catch(Exception e)
{

}

}
}
}
}



public void paint(Graphics g) {
g.drawString("Successfully connected to mysql",25,25);
}

}


This is the output i got:


init:


deps-jar:


compile-single:


run-single:


com.mysql.jdbc.Driver


BUILD SUCCESSFUL (total time: 0 seconds)

Thanks for any help

   <<Less

Re: Data's not inserting into database in NetBeans5.5.

Posted By:   Sachin_M  
Posted On:   Wednesday, August 1, 2007 03:22 AM

Hi

It seems to be that mysql-connector-java-5.0.4-bin.jar file is not founded on the classpath.How i can add this to main class library of the project.I have tried the same code in servlets.I added the mysql-connector jar file to WEB-INF/lib folder and its working.I tried the same code for Swing Applet,but i don't know where to add the connector jar file.
About | Sitemap | Contact