📄 ticket.java
字号:
package ticket;
import java.sql.*;
public class ticket
{
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=preconcert";
String user="sa";
String password="";
Connection conn =null;
Statement stmt =null;
String sql =null;
ResultSet rs =null;
int n;
private String name="";
public void setname(String n)
{
this.name = n;
}
public String getname()
{
return this.name;
}
private String type="";
public void settype(String t)
{
this.type = t;
}
public String gettype()
{
return this.type;
}
private String function="";
public void setnumber(String n)
{
this.function = n;
}
public String getnumber()
{
return this.function;
}
private String year ="";
public void setyear(String y)
{
this.year = y;
}
public String getyear()
{
return this.year;
}
private String month ="";
public void setmonth(String m)
{
this.month = m;
}
public String getmonth()
{
return this.month;
}
private String date = "";
public void setdate(String d)
{
this.date = d;
}
public String getdate()
{
return this.date;
}
public ticket()
{
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
conn= DriverManager.getConnection(url,user,password);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
public boolean insert()
{
sql = "insert into ticket (name,type,function,year,month,date) values(?,?,?,?,?,?)";
try{
PreparedStatement ps = conn.prepareStatement(sql);
ps.setString(1,this.name);
ps.setString(2,this.type);
ps.setString(3,this.function);
ps.setString(4,this.year);
ps.setString(5,this.month);
ps.setString(6,this.date);
n=ps.executeUpdate();
if(n==1)
return true;
else
return false;
}
catch(Exception e)
{
return false;
}
}
public boolean del(int id)
{
sql = "delete from ticket where id=?";
try{
PreparedStatement ps = conn.prepareStatement(sql);
ps.setInt(1,id);
n=ps.executeUpdate();
if(n==1)
return true;
else
return false;
}
catch(Exception e)
{
return false;
}
}
public void close()
{
try{
stmt.close();
conn.close();
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -