📄 testsql.java
字号:
/*
* TestSql.java
*
* Created on 2006年8月9日, 下午8:45
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package PUBLIC;
import java.sql.*;
/**
*
* @author fish
*/
//本类是数据库公用代码模块,所有代码都是基本的数据库连接语句,所以不做注释
public class TestSql {
public Connection conn=null;
public Statement sql;
public TestSql(){
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
}
try {
conn=DriverManager.getConnection("jdbc:odbc:OnlineTest"); //在这里连接你的ODBC数据源
} catch (SQLException ex) {
ex.printStackTrace();
}
try {
sql=conn.createStatement();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public String FormatStr(String s){ //转化汉字
try{
if(s==null)
return null;
else
{
s = ChangeToHtml(s);
byte b[]=s.getBytes("ISO-8859-1");
s = new String(b);
return s;
}
}catch(Exception e){
return null;
}
}
private String ChangeToHtml(String s) { //特殊字符转为Html
s = Replace(s,"&","&");
s = Replace(s,"<","<");
s = Replace(s,">",">");
s = Replace(s,"\t"," ");
s = Replace(s,"\r\n","\n");
s = Replace(s,"\n","<br>");
s = Replace(s," "," ");
s = Replace(s,"'","'");
s = Replace(s,"\\","\");
return s;
}
private String Replace(String source,String oldString,String newString) { //字符转换函数
if(source == null) return null;
StringBuffer output = new StringBuffer();
int lengOfsource = source.length();
int lengOfold = oldString.length();
int posStart = 0;
int pos;
while((pos = source.indexOf(oldString,posStart)) >= 0) {
output.append(source.substring(posStart,pos));
output.append(newString);
posStart = pos + lengOfold;
}
if(posStart < lengOfsource) {
output.append(source.substring(posStart));
}
return output.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -