转自:
http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetAvailableSqlTypesInADatabase.htm
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = getMySqlConnection();
System.out.println("Got Connection.");
Statement st = conn.createStatement();
st.executeUpdate("drop table survey;");
st.executeUpdate("create table survey (id int,name varchar(30));");
st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
ResultSet rs = null;
DatabaseMetaData meta = conn.getMetaData();
rs = meta.getTypeInfo();
while (rs.next()) {
// Get the database-specific type name
String typeName = rs.getString("TYPE_NAME");
// Get the java.sql.Types type to which this
// database-specific type is mapped
short dataType = rs.getShort("DATA_TYPE");
// Get the name of the java.sql.Types value.
System.out.println("type name="+typeName);
System.out.println("dataType="+dataType);
System.out.println("jdbcType="+dataType);
}
st.close();
conn.close();
}
private static Connection getHSQLConnection() throws Exception {
Class.forName("org.hsqldb.jdbcDriver");
System.out.println("Driver Loaded.");
String url = "jdbc:hsqldb:data/tutorial";
return DriverManager.getConnection(url, "sa", "");
}
public static Connection getMySqlConnection() throws Exception {
String driver = "org.gjt.mm.mysql.Driver";
String url = "jdbc:mysql://localhost/demo2s";
String username = "oost";
String password = "oost";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
public static Connection getOracleConnection() throws Exception {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:caspian";
String username = "mp";
String password = "mp2";
Class.forName(driver); // load Oracle driver
Connection conn = DriverManager.getConnection(url, username, password);
return conn;
}
}
分享到:
相关推荐
This book is the definitive reference on PL/SQL, considered throughout the database community to be the best Oracle programming book available. Like its predecessors, this fifth edition of Oracle PL/...
Overview Absolute Database: Delphi database with SQL support.Absolute Database lets you forget the Borland Database Engine (BDE). This BDE replacement is the compact, high-speed, robust and easy-to-...
- Bug 4918586: National character set datatypes (NCHAR, NVARCHAR2, NCLOB) are converted to the database character set datatypes (CHAR, VARCHAR2, CLOB) in the Run PL/SQL dialog box. Workaround: ...
An intent lock indicates that SQL Server wants to acquire a shared (S) lock or exclusive (X) lock on some of the resources lower down in the hierarchy. For example, a shared intent lock placed at the ...
In a nonclustered index, the leaf level contains each index key, plus a bookmark that tells SQL Server where to find the data row corresponding to the key in the index. A bookmark can take one of two ...
From there, the examples mirror the sqlite3 examples, including creating a database and table, loading data in a CSV input file into a database table, updat‐ ing records in a table using a CSV input...
When you don't have a SQL Server available When you want your footprint as small as possible and can't afford SQL Express When you want to manipulate or cache SQL data When you need to write highly...
CHAPTER 4 SQL in a Nutshell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.2 Logging ...
structure data from PDB files can now be used, and are stored in a database for lookup later dissect structures form can now show a list of known structures (pdb, mono, ...) Added a "revert to saved ...
NHibernate is used in Orchard CMS for data access, allowing developers to work with databases using a higher-level, object-oriented API rather than SQL queries. This abstraction layer makes it easier...
A built-in dialog designer to request parameters before running a report, plus a macro-language interpreter (four languages available - C++Script, PascalScript, BasicScript, JScript) that handles non-...
ps.setBinaryStream(2, in, in.available()); ps.executeUpdate(); ps.close(); // 读取操作 PreparedStatement psRead = conn.prepareStatement("SELECT * FROM tb_file WHERE filename = ?"); psRead....
This means that you do a binary search in the page list in log M time and get the value in O(1) time within a page. RaptorDB starts off by loading the page list and it is good to go from there and...
s should restrict master as well.0.00 of 5 Closed8417 TCustomSQLDataSet.GetFieldData implementation0.00 of 5 Closed8229 Error in code when database doesn't support schema/owner names5.00 of 5 ...
9.5.2. Create a date from database 9.5.3. Create dates from an array 9.6. Constants for General Date Functions 9.6.1. Using Constants 9.6.2. List of All Constants 9.6.3. Self-Defined OUTPUT ...
If you use constants in your value, and these constants belong to a ; dynamically loaded extension (either a PHP extension or a Zend extension), ; you may only use these constants *after* the line ...
Lazy Database Connecting......................................................................................28 Testing your Connection...................................................................