Академический Документы
Профессиональный Документы
Культура Документы
*;
public class db
{
static final String
static final String
static final String
static final String
JDBC_DRIVER="com.mysql.jdbc.Driver";
DB_URL = "jdbc:mysql://localhost:3306/userdb";
USER="root";
PASS="toor";
} catch (Exception e) {
e.printStackTrace();
}
=========================================================================
resp2
import java.sql.Connection;
import java.sql.DriverManager;
/**
*
* @author Nadun
*/
public class DBClass {
static private Connection connection;
public static Connection getConnection() throws Exception{
if(connection == null){
//JDBC
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:mysql://localhost:330
6/stock", "root", "123");
}
return connection;
}
===============================================
rep3
String sql="INSERT INTO donors (unit,name) VALUES (?,?)";
//put the rest of the sentence
try {
PreparedStatement pdt = cn.prepareStatement(sql);
pdt.setString(1, jTextField2.getText();
pdt.setString(2, jTextField3.getText();
//put the rest of the code
int n1=pdt.executeUpdate();
if(n1>0)
{
JOptionPane.showMessageDialog(null,"Inserted Successfully!");
}
}catch (SQLException ex) { }
----------------------------------------------------------------------------------------------------------------------------package JavaDB_001;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import javax.swing.*;
public class Work extends JFrame{
JLabel JL_fname,JL_lname,JL_age,JL_id;
JTextField JT_fname,JT_lname,JT_age,JT_id;
JButton btn_insert,btn_update,btn_delete;
public Work(){
//button insert
btn_insert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
theQuery("insert into users (fname,lname,age) values('"+JT_fname.ge
tText()+"','"+JT_lname.getText()+"',"+JT_age.getText()+")");
}
catch(Exception ex){}
}
});
//button update
btn_update.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{