?? yoursqlcmd.java
字號:
package code;
import java.io.*;
import java.sql.*;
import java.net.*;
import java.util.*;
public class yourSQLCmd {
/**
* @param args
*/
static Vector tableList;
public static void main(String[] args) throws IOException,SQLException{
// TODO Auto-generated method stub
String inputstring;
BufferedReader stdin,loadFileReader;
BufferedReader startReader=(BufferedReader)null;
Connection con;
Statement stmt;
String fName,tableName=null,inputString,cmdString,colTypeName,dbType,
parameterString,loadString,fieldString,readString;
StringBuffer lineOut,prepareBuffer,valuesBuffer,inputBuffer;
boolean echo=false;
stdin = new BufferedReader(new InputStreamReader(System.in));
try
{
Class.forName("code.yourSQLDriver");
} catch (ClassNotFoundException e) {
System.err.println(
"JDBC Driver could not be registered!!\n");
}
fName = ".";
if ( args.length > 0 ) fName = args[0];
con = dbConnect(fName);
if ( con == (Connection)null )
{
fName = ".";
con = dbConnect(fName);
}
stmt = con.createStatement();
// for(int ttt=0;ttt<1;ttt++)
// {
// inputstring=stdin.readLine();
// stmt.executeUpdate(inputstring);
// }
String sql="select name age from bjj ;";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
System.out.println(rs.getString("name"));
System.out.println(rs.getInt("age"));
}
}
private static Connection dbConnect(String tinySQLDir) throws SQLException
{
Connection con=null;
DatabaseMetaData dbMeta;
File conPath;
File[] fileList;
String tableName;
ResultSet tables_rs;
conPath = new File(tinySQLDir);
fileList = conPath.listFiles();
if ( fileList == null )
{
System.out.println(tinySQLDir + " is not a valid directory.");
return (Connection)null;
} else {
System.out.println("Connecting to " + conPath.getAbsolutePath());
con = DriverManager.getConnection("jdbc:yourSQL:" + conPath, "", "");
}
// dbMeta = con.getMetaData();
// tables_rs = dbMeta.getTables(null,null,null,null);
// tableList = new Vector();
// while ( tables_rs.next() )
// {
// tableName = tables_rs.getString("TABLE_NAME");
// tableList.addElement(tableName);
// }
// if ( tableList.size() == 0 )
// System.out.println("There are no tinySQL tables in this directory.");
// else
// System.out.println("There are " + tableList.size() + " tinySQL tables"
// + " in this directory.");
return con;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -