是否有关于如何将数据从 PostgreSQL 插入或检索到 android studio 的文档,我正在使用 kotlin
。我是 Android Studio 的新手。我的 MainActivity.kt 和 connectiondb.java
connectiondb.java
public class connectionDb {
Connection connection=null;
public Connection ConnectionDb(){
try{
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/mytransactiondb", "postgres", "root");
} catch (Exception err) {
System.err.println(err.getMessage());
}
return connection;
}
protected void close_connection(Connection con)throws Exception{
con.close();
}
}
主要 Activity .kt
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn_login.setOnClickListener{
val objConnectionDb=connectionDb()
objConnectionDb.connection
Log.i("connectinDb()", "Connected")
}
}
}
提前致谢
最佳答案
尽管我没有在 Android 上使用 PostreSQL,但我得到了这个文档,上面写着。
下面是使用 PostreSQL for Android 插入查询的方法
PreparedStatement st=conn.prepareStatement(”INSERT INTO films (title) ”+”VALUES(?) ;”);
st.setString(1,”On Stranger Tides”);
int rows=st.executeUpdate();
st.close();
通过this link了解更多详情。
关于 here 的更多见解
关于android - 使用postgresql在android studio(kotlin)中插入记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62256940/