当前位置: 技术问答>java相关
请问怎样联接sql数据库,有代码给小第发点过来,谢谢!
来源: 互联网 发布时间:2015-01-06
本文导语: 请问怎样联接sql数据库,有代码给小第发点过来,谢谢! 是不是非要下载个jdbc的驱程,又怎么配置?小弟连不上,谢谢! | 给你看看用VJ++6在Applet中写的代码: try { if (System.getProperty("jav...
请问怎样联接sql数据库,有代码给小第发点过来,谢谢!
是不是非要下载个jdbc的驱程,又怎么配置?小弟连不上,谢谢!
是不是非要下载个jdbc的驱程,又怎么配置?小弟连不上,谢谢!
|
给你看看用VJ++6在Applet中写的代码:
try
{
if (System.getProperty("java.vendor").equals("Microsoft Corp."))
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
else
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dCon = DriverManager.getConnection("jdbc:odbc:MISforCorp","","");
dStm = dCon.createStatement();
String msql= new String("SELECT id, DAY FROM Stationerylist WHERE id in (select min(id) from stationerylist where "+ para.trim() +"and person='"+loginName+"' group by day)order by day");
dRs = dStm.executeQuery(msql);
if(!dRs.next())
{
labStatus.setText("没有找到符合此条件的记录");
}
else
{ dRs = dStm.executeQuery(msql);
lstList.removeAll();
hList.removeAll();
while (dRs.next())
{
lstList.addItem(dRs.getString("DAY").trim().substring(0,10));
hList.addItem(dRs.getString("id"));
}
labStatus.setText("记录已找到!");
}
}
catch(Exception ex)
{
labStatus.setText("查询条件有错");
txfQuery.requestFocus();
}
try
{
if (System.getProperty("java.vendor").equals("Microsoft Corp."))
Class.forName("com.ms.jdbc.odbc.JdbcOdbcDriver");
else
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dCon = DriverManager.getConnection("jdbc:odbc:MISforCorp","","");
dStm = dCon.createStatement();
String msql= new String("SELECT id, DAY FROM Stationerylist WHERE id in (select min(id) from stationerylist where "+ para.trim() +"and person='"+loginName+"' group by day)order by day");
dRs = dStm.executeQuery(msql);
if(!dRs.next())
{
labStatus.setText("没有找到符合此条件的记录");
}
else
{ dRs = dStm.executeQuery(msql);
lstList.removeAll();
hList.removeAll();
while (dRs.next())
{
lstList.addItem(dRs.getString("DAY").trim().substring(0,10));
hList.addItem(dRs.getString("id"));
}
labStatus.setText("记录已找到!");
}
}
catch(Exception ex)
{
labStatus.setText("查询条件有错");
txfQuery.requestFocus();
}